From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0072.outbound.protection.outlook.com [104.47.34.72]) by dpdk.org (Postfix) with ESMTP id 016F96CD4 for ; Fri, 14 Oct 2016 12:54:19 +0200 (CEST) Received: from DM2PR03CA0027.namprd03.prod.outlook.com (10.141.96.26) by DM2PR03MB333.namprd03.prod.outlook.com (10.141.54.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.649.16; Fri, 14 Oct 2016 10:54:18 +0000 Received: from BY2FFO11FD029.protection.gbl (2a01:111:f400:7c0c::182) by DM2PR03CA0027.outlook.office365.com (2a01:111:e400:2428::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.12 via Frontend Transport; Fri, 14 Oct 2016 10:54:17 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD029.mail.protection.outlook.com (10.1.14.212) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.629.5 via Frontend Transport; Fri, 14 Oct 2016 10:54:17 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u9EAs936011436; Fri, 14 Oct 2016 03:54:15 -0700 From: Shreyansh Jain To: CC: , , , Shreyansh Jain Date: Fri, 14 Oct 2016 16:25:25 +0530 Message-ID: <1476442527-30726-3-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476442527-30726-1-git-send-email-shreyansh.jain@nxp.com> References: <1474985551-14219-1-git-send-email-shreyansh.jain@nxp.com> <1476442527-30726-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131209160576411224; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(47776003)(50986999)(33646002)(87936001)(4326007)(11100500001)(85426001)(105606002)(6916009)(2950100002)(86362001)(6666003)(626004)(50466002)(48376002)(81156014)(575784001)(81166006)(2351001)(2906002)(5660300001)(92566002)(356003)(106466001)(110136003)(586003)(36756003)(189998001)(5890100001)(104016004)(229853001)(77096005)(8676002)(50226002)(8936002)(68736007)(97736004)(7846002)(5003940100001)(19580395003)(19580405001)(76176999)(8666005)(305945005)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR03MB333; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD029; 1:E/W/EJcYfv9DeVxQqudWpCSPoY2IRA2TnLyKnaeMFwmgkFswOtw9K5HqfkaDnL1bQYkXPzDQVfY6huNSLUR2SAm5/HU2ZmMfpcOkWpx1ZP3DVZ8HYzRXtM+kKh9aqGEfbUcZxLgEYW8WlB6PKfnWvrfamHDE+iPQoKFRP94lCcTCkhCKahFRuQAlDlXG3HC3YnG6J6APPjmvdwjk0MSj5qo2zIQqfesM3ZlkZ0Kt+LEe5jZwjLPB9PRa19Cksd7LtoUzytd3x8M/HQvj8aphv9TVdHs9nZW6760eHsrb6VqcKOI2jJkoNHxRIzCAOUH4/P29j26HAMRensab+37N6faD7F5jiq6O+nF+4w99Vcmjeq/4b1UtMJPHXtzK5pw7hEnY/yTByPWHFWOH9J/00DVqjSOwcg5RK9R064lZXXLCjDkuVyen0nlCnhitDI0AEM4LZ15dJZZHX09ACESnSsQy9PNPZNeXXP13B1//pdDW+HWH2d7ko1IM71OUNUsJKgs79PVMTvfZDFrwuShBzfiXqqdt1IrXmjyEnJjaDnJ2A19w/2yZj8NwKDWJQau8zEAhjtXQ+TkmbYT3b85PQYZpmu/OXkp7ZyeCj2V0S90vraq56HoREyHC8Khfxw5qP0Tgx1wkxVr0Z2d2lG4YE5v7YG/HKlIgQtOiIN9ANgogwg2zRBvdIfeJHE0cHvRdGXl/t9i12zA6Y3iNAufaMUON5otg37xxhqwDkIMeLFM= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 143ef827-f5b3-4691-c4f8-08d3f42071e3 X-Microsoft-Exchange-Diagnostics: 1; DM2PR03MB333; 2:zwtTpcyN9XkaYFBE/oh9KbSpFDIuUFS0Z7CYJRbCtd5cRcR8SthPXm49NEA7wY1naxNDOF3jSgO1pP3u3/YW4heZ8QbOr/GxOMTHq09bCt8ibQYBrvq7p9LExgMn+/kd7RZUsguw5N56f7kfLRinx/3tNcVnIW202GiVKfIcR/i3Vho17AVYbcOO9b7Z7lkPsBoSSZ0HG5Eh6s0Z+vB8sw==; 3:CdezXo6FEHrr/jWXJ9Y+N5mlPqr7cpvrelaVhDRcGt/kcLDxoXms0lhMJKXj18IBMSNoMtlUhD7I/6KBFUCmEUr/RFHKLa/f+yQIURUNjqrCelw0y0Q98sUaNIMT4i+T12is4Tl5nK9ulVelBeiI+FFDZhtAMrHBRRqJ+a1fscfVf0QsQsmwScSL8KI5PU9Cg+u6lPnkHaMvcDg8fDdamSZs+o2sZq8vkzPMjC40Px+QQn+QXgVAddszvRVLHJfY X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB333; X-Microsoft-Exchange-Diagnostics: 1; DM2PR03MB333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aBhSoZFpNdvnF+471axM28setIlsGxK/as7BDatBH4OHZ5igfx0OM2llxyIhs2zPKliqUHXWS8fh+N/5wyg4hueSBg=; 4:4jmxRg/yUkc4k68GqiJgJinibWUWV/yFjYQEvRBANYFfFdVpeo8mEBDsDeNAlLWxi5DuQWROyp0wTe2s/fKfUzvztZzpkqLtEETrUAo3MHElsPHexqTS6U7xPjLpeesWACIhqhc8BHMB9w1WTcphUtDbftku1yhrMU74idvRCylzJAkrZ1akySaG/YKwPESPH4L0/GBAU8SSYu1wU7MunH1uOvWFg4hgTmSd4ykSrUalV12P7TpKvEZwuCpk9VuFRv10u/eAbYqXljTmWAP5GVHmb38Y0YF0JB7Vuq2J6VtaRd6ZZ29i9KkWmrfnFoGgZY10CmaSvvPdiaGofJs2DWgYVCuZ3D4ejLNd+CXi+HBH4SumZ04ynwfWUyXxafQQK3MqRHxsBXN7bvxowo9ylvrUshsmDfh39xrvjHePLyyCpzIUKE0zkhe4HoXKa7t+XeRJpFcJfYmpn2GlS7YDX2iVDnEEtVo2yxzRyic6xXOqzd/5mOHje90+gLsucYedCeyfyvJq+9Uz5D6b/kDTtaOsY7MDIiRSipTiph0N5H2b9yVz2HWXaBLWR2eqLbii X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13023025)(13024025)(8121501046)(13017025)(13018025)(13015025)(5005006)(3002001)(10201501046)(6055026); SRVR:DM2PR03MB333; BCL:0; PCL:0; RULEID:(400006); SRVR:DM2PR03MB333; X-Forefront-PRVS: 0095BCF226 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR03MB333; 23:T8AFpiZ+cXGNxhiiwqcC7L+hFwKo3zMyU8l4NAnuuU?= =?us-ascii?Q?JCSKNVu9eWVgPhstGP0vjdLW6NtZXgeVBBxvwGeWwqxBN/GxtjsG8PDND9xj?= =?us-ascii?Q?32ci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Ug7155gWSrpFK?= =?us-ascii?Q?xHe2iYMwwT8UAkB+wXCl7+b8l1ocGA/GwvWdK6yGcRaACc3r1cCVLA76Raee?= =?us-ascii?Q?bLw7PntKzJNhMwMskLvsyz41oI2QLBxhpvRwcstjJ0Mi8lOVjGKvtpjvUPw5?= =?us-ascii?Q?yD95A7iTt09D7T//30wU6QTgmDq9v/FPsigZ3qpie5pTWH6KTjGyyNmdOi5J?= =?us-ascii?Q?BtwnMRQU3rncLKaqdZd4JX5BFTvTBIc7+quXtSS6d0+STw2DpqXS1xtVBA61?= =?us-ascii?Q?SnAPPKtvIdIbFDSuV1GE4BYcsxlvaWMVSlSHi9?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR03MB333; 6:edqJ4G9hSx5O+bjCBMzGC+q5pPjaJNQ2e54DNdwSem2tkfltGv2iY8D0Ri+ov6ZVL6/wbpXPasRnGuDdY8EF5WQbn+oC1ASzTjxTcLJZK0u/NOmlqLNjGXCA8MORQypqY1dxvQpLQw6ItxfS2mX+MVd21whBgQcgObSFqXsR9buqv/WjtBV4GJFuLLc2N/pJRikyF3mVEPXSEA3RtcRhlces39VtRS7k/3Ydu5rLe+HPYNs8Pve7cnvs+vIH3cbbiOhZYd7xcRGG2aFowOAc0lIiwmFhmx07SJwt2vkZVQXk1jSv9hIbetE2UgKGtVX0; 5:/RRacEetkfgjLjqwZoVJacqUeqdyaobbB9kRVsV4zYSwj/FYqnzE7SHE46qkhpFfSn0JxIoXnGL+nRvvDIaOi8nD3l4NJvGieUZfNISMvFWwByPM3LtFkjzHoI3+G8s5DeUGG/hcVHeFqYYMVMxZ0L3wp5u5phkRJsbr152NeehL21ilJBOizu5Gyo2x9phg; 24:IbqLj28EvXCaJozNSBZfkRSV20TE34eGjFKRbZb5aMgTe1fAsmv00iBvvCkofUq5HhCfPKMPiJTfHhZV4VwA+bJ1VYzRj40XI0e6BBbbwnE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR03MB333; 7:4Y2dyE6yNOvSZa/uQTte6dPLmEHHDVnG0r9MWR1sh2V/fEl+UR+3S6nsuVOf2hfUmbJmpWkF9sswFZpNHsrz6rAWC+YEMvoaH0Pe3GnyJqxfPVlT21FiywxM7Bw2joG+vQ5gIG9wGIqlDi0eU673GsuxrwnRnk5F2pdc5opbWdw830BxfgdI6aRcJzslKkfH0EX3+I12Jh9RHCkdNmTlOPHB0PXCQiCSYVQSq/93vh1mRtSi3zMYv+G2n15tcz9ylvLH6eSModo3MfQxRHzqdrNQzx4+q80hJQmvD1LcCrE4FImKfJ04RMase+DJ+krIYDllq6BZFnAp4WhKfYCmKQkg0kUQiiWRLe0poXDZy14= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2016 10:54:17.4383 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR03MB333 Subject: [dpdk-dev] [PATCH v2 2/4] eal: generalize PCI map/unmap resource to EAL X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Oct 2016 10:54:20 -0000 From: Jan Viktorin The functions pci_map_resource, pci_unmap_resource are generic so the pci_* prefix can be omitted. The functions are moved to the eal_common_dev.c so they can be reused by other infrastructure. Signed-off-by: Jan Viktorin Signed-off-by: Shreyansh Jain --- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 +- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 ++ lib/librte_eal/common/eal_common_dev.c | 39 +++++++++++++++++++++++++ lib/librte_eal/common/eal_common_pci.c | 39 ------------------------- lib/librte_eal/common/eal_common_pci_uio.c | 16 +++++----- lib/librte_eal/common/include/rte_dev.h | 32 ++++++++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 32 -------------------- lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +- lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 5 ++-- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 ++ 10 files changed, 89 insertions(+), 82 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 8b3ed88..7ed0115 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -228,7 +228,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, /* if matching map is found, then use it */ offset = res_idx * pagesz; - mapaddr = pci_map_resource(NULL, fd, (off_t)offset, + mapaddr = rte_eal_map_resource(NULL, fd, (off_t)offset, (size_t)dev->mem_resource[res_idx].len, 0); close(fd); if (mapaddr == MAP_FAILED) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 2f81f7c..11d9f59 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -170,6 +170,8 @@ DPDK_16.11 { rte_delay_us_callback_register; rte_eal_dev_attach; rte_eal_dev_detach; + rte_eal_map_resource; + rte_eal_unmap_resource; rte_eal_vdrv_register; rte_eal_vdrv_unregister; diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 4f3b493..457d227 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -151,3 +152,41 @@ err: RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", name); return -EINVAL; } + +/* map a particular resource from a file */ +void * +rte_eal_map_resource(void *requested_addr, int fd, off_t offset, size_t size, + int additional_flags) +{ + void *mapaddr; + + /* Map the Memory resource of device */ + mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE, + MAP_SHARED | additional_flags, fd, offset); + if (mapaddr == MAP_FAILED) { + RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s" + " (%p)\n", __func__, fd, requested_addr, + (unsigned long)size, (unsigned long)offset, + strerror(errno), mapaddr); + } else + RTE_LOG(DEBUG, EAL, " Device memory mapped at %p\n", mapaddr); + + return mapaddr; +} + +/* unmap a particular resource */ +void +rte_eal_unmap_resource(void *requested_addr, size_t size) +{ + if (requested_addr == NULL) + return; + + /* Unmap the Memory resource of device */ + if (munmap(requested_addr, size)) { + RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n", + __func__, requested_addr, (unsigned long)size, + strerror(errno)); + } else + RTE_LOG(DEBUG, EAL, " Device memory unmapped at %p\n", + requested_addr); +} diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 638cd86..464acc1 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -67,7 +67,6 @@ #include #include #include -#include #include #include @@ -114,44 +113,6 @@ static struct rte_devargs *pci_devargs_lookup(struct rte_pci_device *dev) return NULL; } -/* map a particular resource from a file */ -void * -pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size, - int additional_flags) -{ - void *mapaddr; - - /* Map the PCI memory resource of device */ - mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE, - MAP_SHARED | additional_flags, fd, offset); - if (mapaddr == MAP_FAILED) { - RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n", - __func__, fd, requested_addr, - (unsigned long)size, (unsigned long)offset, - strerror(errno), mapaddr); - } else - RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr); - - return mapaddr; -} - -/* unmap a particular resource */ -void -pci_unmap_resource(void *requested_addr, size_t size) -{ - if (requested_addr == NULL) - return; - - /* Unmap the PCI memory resource of device */ - if (munmap(requested_addr, size)) { - RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n", - __func__, requested_addr, (unsigned long)size, - strerror(errno)); - } else - RTE_LOG(DEBUG, EAL, " PCI memory unmapped at %p\n", - requested_addr); -} - /* * If vendor/device ID match, call the probe() function of the * driver. diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c index 367a681..3402518 100644 --- a/lib/librte_eal/common/eal_common_pci_uio.c +++ b/lib/librte_eal/common/eal_common_pci_uio.c @@ -75,9 +75,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev) return -1; } - void *mapaddr = pci_map_resource(uio_res->maps[i].addr, - fd, (off_t)uio_res->maps[i].offset, - (size_t)uio_res->maps[i].size, 0); + void *mapaddr = rte_eal_map_resource( + uio_res->maps[i].addr, fd, + (off_t)uio_res->maps[i].offset, + (size_t)uio_res->maps[i].size, + 0); /* fd is not needed in slave process, close it */ close(fd); if (mapaddr != uio_res->maps[i].addr) { @@ -88,11 +90,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev) if (mapaddr != MAP_FAILED) { /* unmap addrs correctly mapped */ for (j = 0; j < i; j++) - pci_unmap_resource( + rte_eal_unmap_resource( uio_res->maps[j].addr, (size_t)uio_res->maps[j].size); /* unmap addr wrongly mapped */ - pci_unmap_resource(mapaddr, + rte_eal_unmap_resource(mapaddr, (size_t)uio_res->maps[i].size); } return -1; @@ -150,7 +152,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) return 0; error: for (i = 0; i < map_idx; i++) { - pci_unmap_resource(uio_res->maps[i].addr, + rte_eal_unmap_resource(uio_res->maps[i].addr, (size_t)uio_res->maps[i].size); rte_free(uio_res->maps[i].path); } @@ -167,7 +169,7 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res) return; for (i = 0; i != uio_res->nb_maps; i++) { - pci_unmap_resource(uio_res->maps[i].addr, + rte_eal_unmap_resource(uio_res->maps[i].addr, (size_t)uio_res->maps[i].size); if (rte_eal_process_type() == RTE_PROC_PRIMARY) rte_free(uio_res->maps[i].path); diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index e73b0fa..277c07b 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -234,6 +234,38 @@ int rte_eal_dev_attach(const char *name, const char *devargs); */ int rte_eal_dev_detach(const char *name); +/* + * @internal + * Map a particular resource from a file. + * + * @param requested_addr + * The starting address for the new mapping range. + * @param fd + * The file descriptor. + * @param offset + * The offset for the mapping range. + * @param size + * The size for the mapping range. + * @param additional_flags + * The additional flags for the mapping range. + * @return + * - On success, the function returns a pointer to the mapped area. + * - On error, the value MAP_FAILED is returned. + */ +void *rte_eal_map_resource(void *requested_addr, int fd, off_t offset, + size_t size, int additional_flags); + +/** + * @internal + * Unmap a particular resource. + * + * @param requested_addr + * The address for the unmapping range. + * @param size + * The size for the unmapping range. + */ +void rte_eal_unmap_resource(void *requested_addr, size_t size); + #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[] #define RTE_PMD_EXPORT_NAME(name, idx) \ diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 2c7046f..7d6eef5 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -399,38 +399,6 @@ int rte_eal_pci_map_device(struct rte_pci_device *dev); void rte_eal_pci_unmap_device(struct rte_pci_device *dev); /** - * @internal - * Map a particular resource from a file. - * - * @param requested_addr - * The starting address for the new mapping range. - * @param fd - * The file descriptor. - * @param offset - * The offset for the mapping range. - * @param size - * The size for the mapping range. - * @param additional_flags - * The additional flags for the mapping range. - * @return - * - On success, the function returns a pointer to the mapped area. - * - On error, the value MAP_FAILED is returned. - */ -void *pci_map_resource(void *requested_addr, int fd, off_t offset, - size_t size, int additional_flags); - -/** - * @internal - * Unmap a particular resource. - * - * @param requested_addr - * The address for the unmapping range. - * @param size - * The size for the unmapping range. - */ -void pci_unmap_resource(void *requested_addr, size_t size); - -/** * Probe the single PCI device. * * Scan the content of the PCI bus, and find the pci device specified by pci diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index 1786b75..5c34421 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -347,7 +347,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, if (pci_map_addr == NULL) pci_map_addr = pci_find_max_end_va(); - mapaddr = pci_map_resource(pci_map_addr, fd, 0, + mapaddr = rte_eal_map_resource(pci_map_addr, fd, 0, (size_t)dev->mem_resource[res_idx].len, 0); close(fd); if (mapaddr == MAP_FAILED) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index 5f478c5..5ad8cbe 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -465,7 +465,8 @@ pci_vfio_map_resource(struct rte_pci_device *dev) void *map_addr = NULL; if (memreg[0].size) { /* actual map of first part */ - map_addr = pci_map_resource(bar_addr, vfio_dev_fd, + map_addr = rte_eal_map_resource(bar_addr, + vfio_dev_fd, memreg[0].offset, memreg[0].size, MAP_FIXED); @@ -477,7 +478,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev) void *second_addr = RTE_PTR_ADD(bar_addr, memreg[1].offset - (uintptr_t)reg.offset); - map_addr = pci_map_resource(second_addr, + map_addr = rte_eal_map_resource(second_addr, vfio_dev_fd, memreg[1].offset, memreg[1].size, MAP_FIXED); diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 83721ba..22b5b59 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -174,6 +174,8 @@ DPDK_16.11 { rte_delay_us_callback_register; rte_eal_dev_attach; rte_eal_dev_detach; + rte_eal_map_resource; + rte_eal_unmap_resource; rte_eal_vdrv_register; rte_eal_vdrv_unregister; -- 2.7.4