From patchwork Mon Jun 29 02:56:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 5902 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id D5731C634; Mon, 29 Jun 2015 04:57:44 +0200 (CEST) Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by dpdk.org (Postfix) with ESMTP id C0AEAC634 for ; Mon, 29 Jun 2015 04:57:41 +0200 (CEST) Received: by pactm7 with SMTP id tm7so97224446pac.2 for ; Sun, 28 Jun 2015 19:57:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qPBB114XjV67lt/TWyTJAy8TDlklp+r4nGqH/wZsPCg=; b=Y3rBAV3lssfadSA98Ez+jaXxslpaWHKA0qz1nZmiio1BSWAq2U87FSOjqAcO8fNUyo 94WVu21KmwhEQlltQsymJYZWU7xBI1Rknp9bQjdNJTiZR51NQwyR8vriHZDHe4hWwT/n IWmpXYmKrDaVz5iQMeEE8OzPE/atDLxxk5F9BPMbpPdff/QCIgyllW7HxvABD4NaDjQr 2NdiiHHLRfT6fzcJqZLiEF2EySimmjJTwPhq3SztUTeL9wIkYt06by+GMf1bK1tFY7BL YhDTQWYSPpR3ub6A7R+0B7GQqJ+2WU/l/7PMCSgJQBXarp9QpxxtywRSLjE8RmGjmZYi ywMQ== X-Gm-Message-State: ALoCoQl4J2BWn3I/L2oXN0cmvQ4nxvwv+ytVKNI5HTYe7hlQ1pIhugFQ8tLZFMwpgD3ODdPwZNPV X-Received: by 10.70.90.162 with SMTP id bx2mr21405416pdb.60.1435546660965; Sun, 28 Jun 2015 19:57:40 -0700 (PDT) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id bi4sm40303927pbc.56.2015.06.28.19.57.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 28 Jun 2015 19:57:40 -0700 (PDT) From: Tetsuya Mukawa To: dev@dpdk.org Date: Mon, 29 Jun 2015 11:56:48 +0900 Message-Id: <1435546610-4533-7-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435546610-4533-1-git-send-email-mukawa@igel.co.jp> References: <1432016513-8456-5-git-send-email-mukawa@igel.co.jp> <1435546610-4533-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v3 6/8] eal: Consolidate pci_map/unmap_resource() of linuxapp and bsdapp 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: "Tetsuya.Mukawa" The patch consolidates below functions, and implemented in common eal code. - pci_map_resource() - pci_unmap_resource() Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/bsdapp/eal/eal_pci.c | 22 ---------------- lib/librte_eal/common/eal_common_pci.c | 40 +++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 11 ++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 41 ------------------------------ lib/librte_eal/linuxapp/eal/eal_pci_init.h | 5 ---- 5 files changed, 51 insertions(+), 68 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 56dc98c..92a9fcf 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -96,28 +96,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, 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; -} - static int pci_uio_map_secondary(struct rte_pci_device *dev) { diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 00547d9..c4b24bc 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include @@ -98,6 +99,45 @@ 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); +} + /* Map pci device */ static int pci_map_device(struct rte_pci_device *dev) diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index bd1ef4e..475d2dc 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -365,6 +365,17 @@ int rte_eal_pci_scan(void); */ int rte_eal_pci_probe(void); +/** + * Map pci resouce. + */ +void *pci_map_resource(void *requested_addr, int fd, off_t offset, + size_t size, int additional_flags); + +/** + * Map pci resouce. + */ +void pci_unmap_resource(void *requested_addr, size_t size); + #ifdef RTE_LIBRTE_EAL_HOTPLUG /** * Probe the single PCI device. diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 5c30469..1d5a13b 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -33,7 +33,6 @@ #include #include -#include #include #include @@ -142,46 +141,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) -{ - 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); -} - /* parse the "resource" sysfs file */ static int pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h index d9d1878..d426b27 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h @@ -42,14 +42,9 @@ 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 /* unmap IGB_UIO resource prototype */ void pci_uio_unmap_resource(struct rte_pci_device *dev);