From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0048.outbound.protection.outlook.com [104.47.41.48]) by dpdk.org (Postfix) with ESMTP id F1CEC374D for ; Mon, 24 Oct 2016 13:59:16 +0200 (CEST) Received: from BN6PR03CA0050.namprd03.prod.outlook.com (10.173.137.12) by SN1PR0301MB1630.namprd03.prod.outlook.com (10.162.130.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12; Mon, 24 Oct 2016 11:59:13 +0000 Received: from BN1BFFO11FD023.protection.gbl (2a01:111:f400:7c10::1:141) by BN6PR03CA0050.outlook.office365.com (2603:10b6:404:4c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12 via Frontend Transport; Mon, 24 Oct 2016 11:59:13 +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 BN1BFFO11FD023.mail.protection.outlook.com (10.58.144.86) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.669.7 via Frontend Transport; Mon, 24 Oct 2016 11:59:13 +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 u9OBwEMM008267; Mon, 24 Oct 2016 04:59:10 -0700 From: Shreyansh Jain To: CC: , , , Shreyansh Jain Date: Mon, 24 Oct 2016 17:29:21 +0530 Message-ID: <1477310380-17944-3-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477310380-17944-1-git-send-email-shreyansh.jain@nxp.com> References: <1476539108-13170-1-git-send-email-shreyansh.jain@nxp.com> <1477310380-17944-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131217839534973395; (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)(76176999)(87936001)(5890100001)(50986999)(36756003)(48376002)(19580395003)(19580405001)(6666003)(11100500001)(626004)(5660300001)(2906002)(8936002)(77096005)(110136003)(50466002)(2950100002)(6916009)(5003940100001)(4326007)(189998001)(586003)(50226002)(97736004)(33646002)(104016004)(305945005)(86362001)(575784001)(7846002)(92566002)(68736007)(229853001)(2351001)(85426001)(105606002)(81156014)(81166006)(8666005)(106466001)(8676002)(356003)(47776003)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR0301MB1630; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD023; 1:MmEvUy4ZZSwCoyWwSrd3yQvT7zElqoj/VaO/FSd7R+Uma5fRgXb7/T/sinCFjyMIhmZ/5tuoerExfCrSJqPYeEWCWrNa20ohbfR9qktkqHjOQ+jUFS7NuIpm3z2sJeigvhv/H0LvhTmeP24GZjB8gdGREw3spmd0/XiCJW6r8lnWQL9EYrBEHPTC/F/Mm8R4ndT9/B7M6VWaHZbIwiHm6P/tRZP2VHcpIJczlnoRyumS67H+azL9hLG2/X5rgUcHuKxB//Diw+MVG/0OrVtE08Ca7OkYiPnQ5W9aHwYrvY9EiBHxJO7Ha+VADg9ZS+y/Y9uT2gzzKGiMeT/R90Ym2Co/KMmHv6jopaMRuc8Txxe9XA//43Z3gvdnW8pXP27cKk6BxZ85OeBpNU7UuKQizaDsLIGm1TSHnUp9wdUaPj5G/cNyvgxhbVG9sLh43DCbkFDclQDU0SYes1ELg/K/HEp/pZGBVI0kcd3MGXICymBJFHX3CoqcBlhpqD2qBAWH7S+h0tKxa5mCz/n/TaU8+dFnhy4iOvjFAgrpRKbkuA4E8XuwWfyhlZOujFocohykGjt7lBmMMcRU1sljpd9ojtmBsGU7j7gy56yj7VxrgemrhbsR6kilShAPUA8UcJATQx2YFi5aLcz22KFPgWQNdYtR/7UKUKOWnR1CugWPsAQt83xYjYtf+ibIGfLelX400tdKl+ueeqa6CH7NJBJgaUIsfkymDoo9gX6Yl0659HU= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 0e96c2e5-3233-48e9-c072-08d3fc052c21 X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB1630; 2:2afjZjSO/OB94UPf05X+BofS+r0np2QzatWg3X9wjzvH6ecbQbZMh8i8FO8yfO+dfCuW5wcDQOjl4QkgUdROUP7tjya0p+VJgVC7gSifH3LkzyMlkPOpGoSqXcJuZdHLCaVM2GQ1lr2fA2Elk1+aX2coDstjBtZcuXBZ4Om1FU9Hfusvska6E9PeS4J/FyUoh5FhOLVGHK8s64rmEVaUdA==; 3:afKAnm+2DOIrKk8uECxjDFBzM3ekqoct3K8kn2QjW+hZ08zeUSNlGwvf6A6wWO2QGqQ9XsFaECpuBBvmAms2ijMc/0f69QEzwToksJCCy2vGCDBPUy65l+ibfWMAzKUHU5J6EYi4IsZTdQIOHILj3/UDMYtpA5iJcAVuAZ+P1OwZIybtVIJRBuWwb/fBuwSISXEhk1jVWCytL2qkua1SEB9CMkqZZkuGgFT7pb7C3j+sgYREAIojzyJuJNTkMOUk X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0301MB1630; X-Microsoft-Exchange-Diagnostics: 1; SN1PR0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eS/fpYqzCFxinJzC8kc7RBcf2hXWQsPoCOi47H9P0DscFJX6QXITCKzJb24fsNaEuXKrPjc+OsEsT7kstmqw==; 4:SyoyLV+mnLYPkXCrXzR1reONvFqjZ8KpRlWxDFGdA2nApM0/KhZJgn1sRl1uq1IGEoU5++B/Z8QuZlT1R0yCIcW/LXjpDbUpNCmBRAzqFcI+7OJARX8FczsWlTxuZ8MArTEpGF4x2eCvO5qB/n+/gehCLZEPH2ZrTQmWd101DqH3OWDEHzGvOqXk8aNDVYF/CFXRT1Ax+8siDLg70nwiM5FqnKOTAIsC2ruot/1IO/tAPU8dWfh5ofnoCfjTL2uRCjvMh4cVx3HUCW7uYJMccHAkNppvNEplAP6vmhXKiRsIatubi5/CloA+vV9ykevB0f2yVVQDM/kYnDlBrbvw+KvJ9I6A4Z1SJaqp5bodALTcx3xy0yvrjoPZ/rLGPu5FT1gH4KgvYPey0RjnajEJul372/Gvf/jvGa7ALB0sBPhUgzA7d/EO+Y+tCB7IcTjGl5by2sKbShVkFPrmrC+jZat0xhveNNwRRdsiJhgZdOp0yyWAIDsfuH3kbKv5V0j3G33JZcvXL8uymDXREHxlxCR5hkQjDKsdwjUJQTUgK16nFMND4QU0201f9HmwLTpF 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)(13017025)(13015025)(13018025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:SN1PR0301MB1630; BCL:0; PCL:0; RULEID:(400006); SRVR:SN1PR0301MB1630; X-Forefront-PRVS: 0105DAA385 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR0301MB1630; 23:QjG5QcJzgFC8rWmyYH09N7hLg700tGLw+jQuQ06?= =?us-ascii?Q?lbq89LDG+grXuHbYOiWgVa3EumzfdKaKw9XuXV8d8rtfzgB+6OYePXiVH444?= =?us-ascii?Q?st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ticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB1630; 7:fpoLjTQK0k5Dc2FVZB4tU500soJQQDLZW91VI+Rv/mCU4JghK0iBMpwOQxII5cT22WP33aX9+/xKSJH1yIAQlC8NNJuMZrn792GDyeteN/y3sokzTSzXX/1XdiVrD6/3QzykXQyCE8DAcps3k1yntjLtC9lIvOs3lciwAq8M26U01eC0GjB8zbbblKaGo56FOVdNXBc6QI+sqNatmYdvfHsYAxCLvjVbx+irYF7H7NlW6VH5rZJK3wpPXnolFn5kYoaJivQFKK+WCEDlOz7O1CZKqVv+1OeLJ/rWSqdJe9CI7v1ZwskeaFM3yRSPkQsdwE5oVE1Ozdk9ngfOAWz3lWeIJtrZHEJ7ycWjL7Hz57g= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2016 11:59:13.3101 (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: SN1PR0301MB1630 Subject: [dpdk-dev] [PATCH v5 02/21] 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: Mon, 24 Oct 2016 11:59:17 -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