[dpdk-dev] [PATCH v3 2/7] pci: use OS generic memory mapping functions
talshn at mellanox.com
talshn at mellanox.com
Thu May 7 14:16:41 CEST 2020
From: Tal Shnaiderman <talshn at mellanox.com>
Changing all of PCIs Unix memory mapping to the
new memory allocation API wrapper.
Change all of PCI mapping function usage in
bus/pci to support the new API.
Signed-off-by: Tal Shnaiderman <talshn at mellanox.com>
---
drivers/bus/pci/bsd/pci.c | 2 +-
drivers/bus/pci/linux/pci_uio.c | 2 +-
drivers/bus/pci/linux/pci_vfio.c | 8 ++++----
drivers/bus/pci/pci_common_uio.c | 2 +-
lib/librte_pci/rte_pci.c | 14 +++++++-------
lib/librte_pci/rte_pci.h | 2 +-
6 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c
index ebbfeb13a..a01dd59f8 100644
--- a/drivers/bus/pci/bsd/pci.c
+++ b/drivers/bus/pci/bsd/pci.c
@@ -192,7 +192,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
(size_t)dev->mem_resource[res_idx].len, 0);
close(fd);
- if (mapaddr == MAP_FAILED)
+ if (mapaddr == NULL)
goto error;
maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c
index 097dc1922..b62200153 100644
--- a/drivers/bus/pci/linux/pci_uio.c
+++ b/drivers/bus/pci/linux/pci_uio.c
@@ -345,7 +345,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
mapaddr = pci_map_resource(pci_map_addr, fd, 0,
(size_t)dev->mem_resource[res_idx].len, 0);
close(fd);
- if (mapaddr == MAP_FAILED)
+ if (mapaddr == NULL)
goto error;
pci_map_addr = RTE_PTR_ADD(mapaddr,
diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index 64cd84a68..422e4b8d7 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -524,11 +524,11 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res,
map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
memreg[0].offset,
memreg[0].size,
- MAP_FIXED);
+ RTE_MAP_FORCE_ADDRESS);
}
/* if there's a second part, try to map it */
- if (map_addr != MAP_FAILED
+ if (map_addr != NULL
&& memreg[1].offset && memreg[1].size) {
void *second_addr = RTE_PTR_ADD(bar_addr,
(uintptr_t)(memreg[1].offset -
@@ -537,10 +537,10 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res,
vfio_dev_fd,
memreg[1].offset,
memreg[1].size,
- MAP_FIXED);
+ RTE_MAP_FORCE_ADDRESS);
}
- if (map_addr == MAP_FAILED || !map_addr) {
+ if (map_addr == NULL) {
munmap(bar_addr, bar->size);
bar_addr = MAP_FAILED;
RTE_LOG(ERR, EAL, "Failed to map pci BAR%d\n",
diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c
index f4dca9da9..793dfd0a7 100644
--- a/drivers/bus/pci/pci_common_uio.c
+++ b/drivers/bus/pci/pci_common_uio.c
@@ -58,7 +58,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
"Cannot mmap device resource file %s to address: %p\n",
uio_res->maps[i].path,
uio_res->maps[i].addr);
- if (mapaddr != MAP_FAILED) {
+ if (mapaddr != NULL) {
/* unmap addrs correctly mapped */
for (j = 0; j < i; j++)
pci_unmap_resource(
diff --git a/lib/librte_pci/rte_pci.c b/lib/librte_pci/rte_pci.c
index d1ab6b414..58e031dcf 100644
--- a/lib/librte_pci/rte_pci.c
+++ b/lib/librte_pci/rte_pci.c
@@ -9,7 +9,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/queue.h>
-#include <sys/mman.h>
#include <rte_errno.h>
#include <rte_interrupts.h>
@@ -138,14 +137,15 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
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) {
+ mapaddr = rte_mem_map(requested_addr, size,
+ RTE_PROT_READ | RTE_PROT_WRITE,
+ RTE_MAP_SHARED | additional_flags, fd, offset);
+ if (mapaddr == NULL) {
RTE_LOG(ERR, EAL,
- "%s(): cannot mmap(%d, %p, 0x%zx, 0x%llx): %s (%p)\n",
+ "%s(): cannot map resource(%d, %p, 0x%zx, 0x%llx): %s (%p)\n",
__func__, fd, requested_addr, size,
(unsigned long long)offset,
- strerror(errno), mapaddr);
+ strerror(rte_errno), mapaddr);
} else
RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr);
@@ -160,7 +160,7 @@ pci_unmap_resource(void *requested_addr, size_t size)
return;
/* Unmap the PCI memory resource of device */
- if (munmap(requested_addr, size)) {
+ if (rte_mem_unmap(requested_addr, size)) {
RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, %#zx): %s\n",
__func__, requested_addr, size,
strerror(errno));
diff --git a/lib/librte_pci/rte_pci.h b/lib/librte_pci/rte_pci.h
index 4087771c1..b721bbf58 100644
--- a/lib/librte_pci/rte_pci.h
+++ b/lib/librte_pci/rte_pci.h
@@ -159,7 +159,7 @@ int rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr);
* 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.
+ * - On error, NULL is returned.
*/
void *pci_map_resource(void *requested_addr, int fd, off_t offset,
size_t size, int additional_flags);
--
2.16.1.windows.4
More information about the dev
mailing list