From patchwork Thu Feb 19 02:49:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 3474 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 1E986B54D; Thu, 19 Feb 2015 03:50:41 +0100 (CET) Received: from mail-pd0-f175.google.com (mail-pd0-f175.google.com [209.85.192.175]) by dpdk.org (Postfix) with ESMTP id 922D1B4D2 for ; Thu, 19 Feb 2015 03:50:27 +0100 (CET) Received: by pdjz10 with SMTP id z10so5657798pdj.0 for ; Wed, 18 Feb 2015 18:50:27 -0800 (PST) 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=dw8kdos23oaX4UHnignXK1J8xsJYVsoxb0bE70Gvtvk=; b=DJXT37dtWmn1mrORUVJtOSfs+SPm9VzQ5Q5djf/lIVQEGb05pZgc/gFtdHt0cX4j4X wTVTNKbFF5qimgrfTwGQNtB5oZnr50F/5L5XafcTdII6sGnIFicCceTCHtbrpRHA5F3T FAB/j+bFPl/ctPxwrjhhxdyV+MRr8Vw1FoavNXozIf+5nMXmi2AHWf4sgpgGrupSh/k/ K2yQiVYMHqiOy09bw86f8P2S/OUmIn/j1DtclfPWwzZmPTcUg05cL3zjnJ5nRCgs7+S1 KPi3HT9dbSLv+i894Gm+SW3dT6JlGiwu17DusqT6bh+KmrFdtioJf92YlQDqmbFWSCXw qv7w== X-Gm-Message-State: ALoCoQm3V/EX6AQYnIfz41UIQBg/Qc2pY8/oiJK7lXV062DY2ni/pyT8ogBShJcoBCeXKI3I0w+3 X-Received: by 10.70.65.105 with SMTP id w9mr419216pds.129.1424314227028; Wed, 18 Feb 2015 18:50:27 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id iy1sm17860786pbb.14.2015.02.18.18.50.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Feb 2015 18:50:26 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Thu, 19 Feb 2015 11:49:40 +0900 Message-Id: <1424314187-25177-10-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424314187-25177-1-git-send-email-mukawa@igel.co.jp> References: <1424060073-23484-12-git-send-email-mukawa@igel.co.jp> <1424314187-25177-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v9 09/14] eal/linux/pci: Add functions for unmapping igb_uio resources 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" The patch adds functions for unmapping igb_uio resources. The patch is only for Linux and igb_uio environment. VFIO and BSD are not supported. v9: - Remove "rte_dev_hotplug.h". - Remove needless "#ifdef". (Thanks to Thomas Monjalon and Neil Horman) - Remove pci_unmap_device(). It will be implemented in later patch. v8: - Fix typo. (Thanks to Iremonger, Bernard) v5: - Fix pci_unmap_device() to check pt_driver. v4: - Add parameter checking. - Add header file to determine if hotplug can be enabled. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/linuxapp/eal/eal_pci.c | 17 ++++++++ lib/librte_eal/linuxapp/eal/eal_pci_init.h | 7 ++++ lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 65 ++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index f593f2c..7349a60 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -167,6 +167,23 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size) 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 */ #define IORESOURCE_MEM 0x00000200 diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h index 1070eb8..e2dd8a5 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h @@ -71,6 +71,13 @@ void *pci_map_resource(void *requested_addr, int fd, off_t offset, /* 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); +#endif /* RTE_LIBRTE_EAL_HOTPLUG */ + #ifdef VFIO_PRESENT #define VFIO_MAX_GROUPS 64 diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index d75eb59..43f47dc 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -404,6 +404,71 @@ pci_uio_map_resource(struct rte_pci_device *dev) return 0; } +#ifdef RTE_LIBRTE_EAL_HOTPLUG +static void +pci_uio_unmap(struct mapped_pci_resource *uio_res) +{ + int i; + + if (uio_res == NULL) + return; + + for (i = 0; i != uio_res->nb_maps; i++) + pci_unmap_resource(uio_res->maps[i].addr, + (size_t)uio_res->maps[i].size); +} + +static struct mapped_pci_resource * +pci_uio_find_resource(struct rte_pci_device *dev) +{ + struct mapped_pci_resource *uio_res; + + if (dev == NULL) + return NULL; + + TAILQ_FOREACH(uio_res, pci_res_list, next) { + + /* skip this element if it doesn't match our PCI address */ + if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr)) + return uio_res; + } + return NULL; +} + +/* unmap the PCI resource of a PCI device in virtual memory */ +void +pci_uio_unmap_resource(struct rte_pci_device *dev) +{ + struct mapped_pci_resource *uio_res; + + if (dev == NULL) + return; + + /* find an entry for the device */ + uio_res = pci_uio_find_resource(dev); + if (uio_res == NULL) + return; + + /* secondary processes - just free maps */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return pci_uio_unmap(uio_res); + + TAILQ_REMOVE(pci_res_list, uio_res, next); + + /* unmap all resources */ + pci_uio_unmap(uio_res); + + /* free uio resource */ + rte_free(uio_res); + + /* close fd if in primary process */ + close(dev->intr_handle.fd); + + dev->intr_handle.fd = -1; + dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN; +} +#endif /* RTE_LIBRTE_EAL_HOTPLUG */ + /* * parse a sysfs file containing one integer value * different to the eal version, as it needs to work with 64-bit values