From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by dpdk.org (Postfix) with ESMTP id 05EB95FEB for ; Thu, 9 Apr 2015 21:40:36 +0200 (CEST) Received: by pabtp1 with SMTP id tp1so53790854pab.2 for ; Thu, 09 Apr 2015 12:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UwfbvReiES7xr4UyV+yb8L3djbfsjQvtJBDQaUbVgkI=; b=FPmsok8YvljY+y2TUerS/Q8oI7tNhuxGkwwyX1iNhYJQSgmTndauRQtHyFB6irIpXi 4rmPFcN0RBqylXecGA4g/1qP6PbBCVobE/62r1fYjEjBOCfrpBKsHhQnw0aXfvs3G+Mb C7gU6eZDAOQF7Mi4bR5P+K4OfjMQY2Lv3XmlsQSeI1hJ8emeNchg63Pl0Fm+r+WeLFxV Wl4Ptp26pG1XNgepaK5VJCmMxVnxTJRvB10KP30thNZSwitber3LgZzRh2xFhrhX+75M oMZranJrB5IDKG6mUYbnoys+SxTvxPGb+aGVV84Sv8zGYuVGkfio0AoonL7GJMhQAH+s iVcQ== X-Received: by 10.68.248.39 with SMTP id yj7mr58206886pbc.58.1428608435456; Thu, 09 Apr 2015 12:40:35 -0700 (PDT) Received: from user-PC.hsd1.ca.comcast.net (c-98-234-176-9.hsd1.ca.comcast.net. [98.234.176.9]) by mx.google.com with ESMTPSA id xv9sm15149298pbc.2.2015.04.09.12.40.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Apr 2015 12:40:35 -0700 (PDT) From: Ravi Kerur To: dev@dpdk.org Date: Thu, 9 Apr 2015 12:40:12 -0700 Message-Id: <1428608412-31191-7-git-send-email-rkerur@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428608412-31191-1-git-send-email-rkerur@gmail.com> References: <1428608301-31033-1-git-send-email-rkerur@gmail.com> <1428608412-31191-1-git-send-email-rkerur@gmail.com> Subject: [dpdk-dev] [PATCH v5 6/8] Move common functions in eal_pci.c 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: Thu, 09 Apr 2015 19:40:36 -0000 Changes in v5 Rebase to latest code. Removed RTE_EXEC_ENV_BSDAPP from earlier changes. Changes in v4 Move common functions in eal_pci.c to librte_eal/common/ eal_common_pci.c file. Following functions are moved to eal_common_pci.c file. void *pci_map_resource(void *requested_addr, const int vfio_fd, const char *devname, off_t offset, size_t size); int pci_addr_comparison(struct rte_pci_addr *addr, struct rte_pci_addr *addr2); int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev); Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in common function. Fix checkpatch warnings and errors. Changes in v3 N/A Changes in v2 N/A Changes in v1 N/A Signed-off-by: Ravi Kerur --- lib/librte_eal/bsdapp/eal/eal_pci.c | 122 ++++----------------------- lib/librte_eal/common/eal_common_pci.c | 130 ++++++++++++++++++++++++++++- lib/librte_eal/common/eal_private.h | 48 +++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 100 +--------------------- lib/librte_eal/linuxapp/eal/eal_pci_init.h | 6 -- lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 36 ++------ lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 17 ++-- 7 files changed, 212 insertions(+), 247 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 30f0232..5669592 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -111,7 +111,7 @@ static struct rte_tailq_elem rte_uio_tailq = { EAL_REGISTER_TAILQ(rte_uio_tailq) /* unbind kernel driver for this device */ -static int +int pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused) { RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented " @@ -119,45 +119,6 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused) return -ENOTSUP; } -/* map a particular resource from a file */ -static void * -pci_map_resource(void *requested_addr, const char *devname, off_t offset, - size_t size) -{ - int fd; - void *mapaddr; - - /* - * open devname, to mmap it - */ - fd = open(devname, O_RDWR); - if (fd < 0) { - RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - devname, strerror(errno)); - goto fail; - } - - /* Map the PCI memory resource of device */ - mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE, - MAP_SHARED, fd, offset); - close(fd); - if (mapaddr == MAP_FAILED || - (requested_addr != NULL && mapaddr != requested_addr)) { - RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):" - " %s (%p)\n", __func__, devname, fd, requested_addr, - (unsigned long)size, (unsigned long)offset, - strerror(errno), mapaddr); - goto fail; - } - - RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr); - - return mapaddr; - -fail: - return NULL; -} - static int pci_uio_map_secondary(struct rte_pci_device *dev) { @@ -172,10 +133,10 @@ pci_uio_map_secondary(struct rte_pci_device *dev) continue; for (i = 0; i != uio_res->nb_maps; i++) { - if (pci_map_resource(uio_res->maps[i].addr, + if (pci_map_resource(uio_res->maps[i].addr, INT_MIN, uio_res->path, (off_t)uio_res->maps[i].offset, - (size_t)uio_res->maps[i].size) + (size_t)uio_res->maps[i].size, 0) != uio_res->maps[i].addr) { RTE_LOG(ERR, EAL, "Cannot mmap device resource\n"); @@ -190,7 +151,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev) } /* map the PCI resource of a PCI device in virtual memory */ -static int +int pci_uio_map_resource(struct rte_pci_device *dev) { int i, j; @@ -257,8 +218,9 @@ pci_uio_map_resource(struct rte_pci_device *dev) maps[j].phaddr = dev->mem_resource[i].phys_addr; maps[j].size = dev->mem_resource[i].len; if (maps[j].addr != NULL || - (mapaddr = pci_map_resource(NULL, devname, (off_t)offset, - (size_t)maps[j].size) + (mapaddr = pci_map_resource(NULL, INT_MIN, devname, + (off_t)offset, + (size_t)maps[j].size, 0) ) == NULL) { rte_free(uio_res); return (-1); @@ -274,6 +236,13 @@ pci_uio_map_resource(struct rte_pci_device *dev) return (0); } +/* map the PCI resource of a PCI device in virtual memory */ +int +pci_map_device(struct rte_pci_device *dev) +{ + return pci_uio_map_resource(dev); +} + /* Scan one pci sysfs entry, and fill the devices list from it. */ static int pci_scan_one(int dev_pci_fd, struct pci_conf *conf) @@ -426,68 +395,11 @@ error: } /* - * If vendor/device ID match, call the devinit() function of the - * driver. + * This function is a no-op in BSD. */ -int -rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) +void +pci_config_space_set(struct rte_pci_device *dev __rte_unused) { - struct rte_pci_id *id_table; - int ret; - - for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) { - - /* check if device's identifiers match the driver's ones */ - if (id_table->vendor_id != dev->id.vendor_id && - id_table->vendor_id != PCI_ANY_ID) - continue; - if (id_table->device_id != dev->id.device_id && - id_table->device_id != PCI_ANY_ID) - continue; - if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && - id_table->subsystem_vendor_id != PCI_ANY_ID) - continue; - if (id_table->subsystem_device_id != dev->id.subsystem_device_id && - id_table->subsystem_device_id != PCI_ANY_ID) - continue; - - struct rte_pci_addr *loc = &dev->addr; - - RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", - loc->domain, loc->bus, loc->devid, loc->function, - dev->numa_node); - - RTE_LOG(DEBUG, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id, - dev->id.device_id, dr->name); - - /* no initialization when blacklisted, return without error */ - if (dev->devargs != NULL && - dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) { - - RTE_LOG(DEBUG, EAL, " Device is blacklisted, not initializing\n"); - return 0; - } - - if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { - /* map resources for devices that use igb_uio */ - ret = pci_uio_map_resource(dev); - if (ret != 0) - return ret; - } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && - rte_eal_process_type() == RTE_PROC_PRIMARY) { - /* unbind current driver */ - if (pci_unbind_kernel_driver(dev) < 0) - return -1; - } - - /* reference driver structure */ - dev->driver = dr; - - /* call the driver devinit() function */ - return dr->devinit(dr, dev); - } - /* return positive value if driver is not found */ - return 1; } /* Init the PCI EAL subsystem */ diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 808b87b..f20fac7 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -61,10 +61,14 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -300,3 +304,123 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver) { TAILQ_REMOVE(&pci_driver_list, driver, next); } + +/* map a particular resource from a file */ +void * +pci_map_resource(void *requested_addr, const int vfio_fd, + const char *devname, off_t offset, size_t size, + int additional_flags) +{ + int fd; + void *mapaddr; + + /* + * For non VFIO environment, vfio_fd is INT_MIN. + */ + if (vfio_fd == INT_MIN) { + /* + * open devname, to mmap it + */ + fd = open(devname, O_RDWR); + if (fd < 0) { + RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", + devname, strerror(errno)); + return MAP_FAILED; + } + } else { + fd = vfio_fd; + } + + /* Map the PCI memory resource of device */ + mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE, + MAP_SHARED | additional_flags, fd, offset); + /* + * Close applies only for non VFIO. + */ + if (vfio_fd == INT_MIN) + close(fd); + + if (mapaddr == MAP_FAILED || + (requested_addr != NULL && mapaddr != requested_addr)) { + RTE_LOG(ERR, EAL, + "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx): %s (%p)\n", + __func__, (devname ? devname : "vfio"), 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; +} + +/* + * If vendor/device ID match, call the devinit() function of the + * driver. + */ +int +rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) +{ + int ret; + struct rte_pci_id *id_table; + + for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) { + + /* check if device's identifiers match the driver's ones */ + if (id_table->vendor_id != dev->id.vendor_id && + id_table->vendor_id != PCI_ANY_ID) + continue; + if (id_table->device_id != dev->id.device_id && + id_table->device_id != PCI_ANY_ID) + continue; + if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && + id_table->subsystem_vendor_id != PCI_ANY_ID) + continue; + if (id_table->subsystem_device_id != dev->id.subsystem_device_id && + id_table->subsystem_device_id != PCI_ANY_ID) + continue; + + struct rte_pci_addr *loc = &dev->addr; + + RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", + loc->domain, loc->bus, loc->devid, loc->function, + dev->numa_node); + + RTE_LOG(DEBUG, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id, + dev->id.device_id, dr->name); + + /* no initialization when blacklisted, return without error */ + if (dev->devargs != NULL && + dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) { + RTE_LOG(DEBUG, EAL, " Device is blacklisted, not initializing\n"); + return 1; + } + + if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { +#ifdef RTE_PCI_CONFIG + /* + * Set PCIe config space for high performance. + * Return value can be ignored. + */ + pci_config_space_set(dev); +#endif + /* map resources for devices that use igb_uio */ + ret = pci_map_device(dev); + if (ret != 0) + return ret; + } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && + rte_eal_process_type() == RTE_PROC_PRIMARY) { + /* unbind current driver */ + if (pci_unbind_kernel_driver(dev) < 0) + return -1; + } + + /* reference driver structure */ + dev->driver = dr; + + /* call the driver devinit() function */ + return dr->devinit(dr, dev); + } + /* return positive value if driver is not found */ + return 1; +} diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index fde1fc9..021b008 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -37,6 +37,7 @@ #include #include +#include /** * Initialize the memzone subsystem (private to eal). @@ -370,4 +371,51 @@ int rte_eal_hugepage_init(void); */ int rte_eal_hugepage_attach(void); +/** + * This function maps a particular resource from a file + * + * This function is private to the EAL. + */ +void * +pci_map_resource(void *requested_addr, const int vfio_fd, + const char *devname, off_t offset, size_t size, + int additional_flags); + +/** + * This function maps PCI resource of a PCI + * device in virtual memory + * + * This function is private to the EAL. + */ +int +pci_uio_map_resource(struct rte_pci_device *dev); + +/** + * This function unbinds kernel driver for this device + * + * This function is private to the EAL. + */ +int +pci_unbind_kernel_driver(struct rte_pci_device *dev); + +/** + * This function maps resources for devices + * that use igb_uio on Linux and it's a + * wrapper for pci_uio_map_resource on BSD. + * + * This function is private to the EAL. + */ +int +pci_map_device(struct rte_pci_device *dev); + +/** + * This function sets PCIe config space for + * high performance. + * It's a NO-OP on BSD. + * + * This function is private to the EAL. + */ +void +pci_config_space_set(struct rte_pci_device *dev); + #endif /* _EAL_PRIVATE_H_ */ diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 9cb0ffd..8aad7e7 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -57,7 +57,7 @@ */ /* unbind kernel driver for this device */ -static int +int pci_unbind_kernel_driver(struct rte_pci_device *dev) { int n; @@ -142,29 +142,6 @@ pci_find_max_end_va(void) return RTE_PTR_ADD(last->addr, last->len); } - -/* 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) @@ -549,7 +526,7 @@ pci_config_max_read_request_size(struct rte_pci_device *dev) return 0; } -static void +void pci_config_space_set(struct rte_pci_device *dev) { if (rte_eal_process_type() != RTE_PROC_PRIMARY) @@ -563,7 +540,7 @@ pci_config_space_set(struct rte_pci_device *dev) } #endif -static int +int pci_map_device(struct rte_pci_device *dev) { int ret = -1; @@ -616,77 +593,6 @@ pci_unmap_device(struct rte_pci_device *dev) } #endif /* RTE_LIBRTE_EAL_HOTPLUG */ -/* - * If vendor/device ID match, call the devinit() function of the - * driver. - */ -int -rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) -{ - int ret; - struct rte_pci_id *id_table; - - for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) { - - /* check if device's identifiers match the driver's ones */ - if (id_table->vendor_id != dev->id.vendor_id && - id_table->vendor_id != PCI_ANY_ID) - continue; - if (id_table->device_id != dev->id.device_id && - id_table->device_id != PCI_ANY_ID) - continue; - if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id && - id_table->subsystem_vendor_id != PCI_ANY_ID) - continue; - if (id_table->subsystem_device_id != dev->id.subsystem_device_id && - id_table->subsystem_device_id != PCI_ANY_ID) - continue; - - struct rte_pci_addr *loc = &dev->addr; - - RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", - loc->domain, loc->bus, loc->devid, loc->function, - dev->numa_node); - - RTE_LOG(DEBUG, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id, - dev->id.device_id, dr->name); - - /* no initialization when blacklisted, return without error */ - if (dev->devargs != NULL && - dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) { - RTE_LOG(DEBUG, EAL, " Device is blacklisted, not initializing\n"); - return 1; - } - - if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { -#ifdef RTE_PCI_CONFIG - /* - * Set PCIe config space for high performance. - * Return value can be ignored. - */ - pci_config_space_set(dev); -#endif - /* map resources for devices that use igb_uio */ - ret = pci_map_device(dev); - if (ret != 0) - return ret; - } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && - rte_eal_process_type() == RTE_PROC_PRIMARY) { - /* unbind current driver */ - if (pci_unbind_kernel_driver(dev) < 0) - return -1; - } - - /* reference driver structure */ - dev->driver = dr; - - /* call the driver devinit() function */ - return dr->devinit(dr, dev); - } - /* return positive value if driver is not found */ - return 1; -} - #ifdef RTE_LIBRTE_EAL_HOTPLUG /* * If vendor/device ID match, call the devuninit() function of the diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h index aa7b755..b8556c3 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h @@ -65,12 +65,6 @@ TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource); extern void *pci_map_addr; void *pci_find_max_end_va(void); -void *pci_map_resource(void *requested_addr, int fd, off_t offset, - size_t size, int additional_flags); - -/* map IGB_UIO resource prototype */ -int pci_uio_map_resource(struct rte_pci_device *dev); - void pci_unmap_resource(void *requested_addr, size_t size); #ifdef RTE_LIBRTE_EAL_HOTPLUG diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index 2d1c69b..ad3f84f 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -48,6 +48,7 @@ #include "rte_pci_dev_ids.h" #include "eal_filesystem.h" #include "eal_pci_init.h" +#include "eal_private.h" void *pci_map_addr = NULL; @@ -90,7 +91,7 @@ pci_uio_set_bus_master(int dev_fd) static int pci_uio_map_secondary(struct rte_pci_device *dev) { - int fd, i; + int i; 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); @@ -101,18 +102,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev) continue; for (i = 0; i != uio_res->nb_maps; i++) { - /* - * open devname, to mmap it - */ - fd = open(uio_res->maps[i].path, O_RDWR); - if (fd < 0) { - RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - uio_res->maps[i].path, strerror(errno)); - return -1; - } - void *mapaddr = pci_map_resource(uio_res->maps[i].addr, - fd, (off_t)uio_res->maps[i].offset, + void *mapaddr = pci_map_resource( + uio_res->maps[i].addr, INT_MIN, + uio_res->maps[i].path, + (off_t)uio_res->maps[i].offset, (size_t)uio_res->maps[i].size, 0); if (mapaddr != uio_res->maps[i].addr) { if (mapaddr == MAP_FAILED) @@ -126,11 +120,8 @@ pci_uio_map_secondary(struct rte_pci_device *dev) uio_res->maps[i].path, uio_res->maps[i].addr); - close(fd); return -1; } - /* fd is not needed in slave process, close it */ - close(fd); } return 0; } @@ -330,7 +321,6 @@ pci_uio_map_resource(struct rte_pci_device *dev) /* Map all BARs */ maps = uio_res->maps; for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) { - int fd; int fail = 0; /* skip empty BAR */ @@ -345,21 +335,11 @@ pci_uio_map_resource(struct rte_pci_device *dev) loc->domain, loc->bus, loc->devid, loc->function, i); - /* - * open resource file, to mmap it - */ - fd = open(devname, O_RDWR); - if (fd < 0) { - RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - devname, strerror(errno)); - return -1; - } - /* try mapping somewhere close to the end of hugepages */ if (pci_map_addr == NULL) pci_map_addr = pci_find_max_end_va(); - mapaddr = pci_map_resource(pci_map_addr, fd, 0, + mapaddr = pci_map_resource(pci_map_addr, INT_MIN, devname, 0, (size_t)dev->mem_resource[i].len, 0); if (mapaddr == MAP_FAILED) fail = 1; @@ -373,10 +353,8 @@ pci_uio_map_resource(struct rte_pci_device *dev) if (fail) { rte_free(uio_res); - close(fd); return -1; } - close(fd); maps[map_idx].phaddr = dev->mem_resource[i].phys_addr; maps[map_idx].size = dev->mem_resource[i].len; diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index aea1fb1..01250ae 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -48,6 +48,7 @@ #include "eal_filesystem.h" #include "eal_pci_init.h" #include "eal_vfio.h" +#include "eal_private.h" /** * @file @@ -799,10 +800,11 @@ 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, - memreg[0].offset, - memreg[0].size, - MAP_FIXED); + map_addr = pci_map_resource(bar_addr, + vfio_dev_fd, NULL, + memreg[0].offset, + memreg[0].size, + MAP_FIXED); } /* if there's a second part, try to map it */ @@ -810,9 +812,10 @@ pci_vfio_map_resource(struct rte_pci_device *dev) && memreg[1].offset && memreg[1].size) { void *second_addr = RTE_PTR_ADD(bar_addr, memreg[1].offset); map_addr = pci_map_resource(second_addr, - vfio_dev_fd, memreg[1].offset, - memreg[1].size, - MAP_FIXED); + vfio_dev_fd, NULL, + memreg[1].offset, + memreg[1].size, + MAP_FIXED); } if (map_addr == MAP_FAILED || !map_addr) { -- 1.9.1