#include <rte_log.h>
#include <rte_pci.h>
#include <rte_bus_pci.h>
+#include <rte_eal_paging.h>
#include <rte_malloc.h>
#include <rte_vfio.h>
#include <rte_eal.h>
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 -
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",
#include <stdlib.h>
#include <stdio.h>
#include <sys/queue.h>
-#include <sys/mman.h>
#include <rte_errno.h>
#include <rte_interrupts.h>
#include <rte_log.h>
#include <rte_bus.h>
+#include <rte_eal_paging.h>
#include <rte_per_lcore.h>
#include <rte_memory.h>
#include <rte_eal.h>
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);
+ rte_strerror(rte_errno), mapaddr);
} else
RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr);
return;
/* Unmap the PCI memory resource of device */
- if (munmap(requested_addr, size)) {
- RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, %#zx): %s\n",
+ if (rte_mem_unmap(requested_addr, size)) {
+ RTE_LOG(ERR, EAL, "%s(): cannot mem unmap(%p, %#zx): %s\n",
__func__, requested_addr, size,
- strerror(errno));
+ rte_strerror(rte_errno));
} else
RTE_LOG(DEBUG, EAL, " PCI memory unmapped at %p\n",
requested_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);