From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f173.google.com (mail-pf0-f173.google.com [209.85.192.173]) by dpdk.org (Postfix) with ESMTP id 31BA08EA0 for ; Mon, 14 Dec 2015 14:01:11 +0100 (CET) Received: by pff63 with SMTP id 63so11006479pff.2 for ; Mon, 14 Dec 2015 05:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mvista-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rjirjDBY46fgVOH4N/xavTTEsbMP82FOyLSs87AROeY=; b=PUz1atYgneYQ2shLhSKDuWLOduTktbK+FOmfY8ija1jeFsL8i18KilFs9po7Zs6TEm nUX8iNL/YBArDxcKvzhPenYmBk8xbtYG/HT+Fe40yFjjrjBEGAUG1vGNzIWVdcQexgCJ D3RRkGz/YzSxERWHMzp5RfU+BX/Zqnld5CBCvYxU2qkJNRe0cfuS++3DUm3Nyrv0KqdP CvTpjqYMm4me7NfOuUPZpQ368eZjWe+Q6iNm0Sq6xgxF40pMslUjF1r1G7FMSU8DkbHp 7/OKQVRQo7KyCHE3qkDlNtvjUFjuMtavCdu9YkDD80NOqq8vYXvgILioocHpIFNEeFGS n0kg== 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=rjirjDBY46fgVOH4N/xavTTEsbMP82FOyLSs87AROeY=; b=US2EqeJAu/h9/JZmGkncK3+tXl57eIogdH7TdPpepiC45G0sOONhymLdV4V6iQYoUQ CpIIKVHr4pYf41O4vZvOyQ0SXy9MgO4vC8BIa0kDkQanfchbkiwjqARWQY1XLlaeWH5y p9KMT07GRKiYvnpulZ+AaTvdhtkYZcw5jSpM2eJ5PeiyHEpeu95RZxmR/It3UjwNDO2k 7TGDRXAhjWzqjNd5q6HBQhmxcUS2wzv0PmYcFB0R3Oa+egyxCOXzlDz+9g4VqMyaEDZR 44rvwWG9exIUxKn8xy7UMOKBxRmq3TaPR7MSf6aeA7z+9Vm3zkydupLfwniRpUsEr4Op Z1yg== X-Gm-Message-State: ALoCoQnJuZf2KG7cYfRosxrpLOb1YHyzo2ZHdHJi/Df4KO+8Rz/fGUw+QI4JpHDZb5zf4hr+zhcx25b1uF4eAj8moljhXyZFyg== X-Received: by 10.98.66.80 with SMTP id p77mr35570614pfa.100.1450098070621; Mon, 14 Dec 2015 05:01:10 -0800 (PST) Received: from santosh-Latitude-E5530-non-vPro.mvista.com ([110.172.16.5]) by smtp.gmail.com with ESMTPSA id 9sm42506405pfn.51.2015.12.14.05.01.07 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Dec 2015 05:01:09 -0800 (PST) From: Santosh Shukla To: dev@dpdk.org Date: Mon, 14 Dec 2015 18:30:28 +0530 Message-Id: <1450098032-21198-10-git-send-email-sshukla@mvista.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1450098032-21198-1-git-send-email-sshukla@mvista.com> References: <1450098032-21198-1-git-send-email-sshukla@mvista.com> Cc: Rakesh Krishnamurthy , Rizwan Ansari Subject: [dpdk-dev] [ [PATCH v2] 09/13] igb_uio: ioport: map iopci region for armv7/v8 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: Mon, 14 Dec 2015 13:01:11 -0000 Module maps iopci region by creating misc device file /dev/igb_ioport. Applicable for non-x86 arch, tested for arm64/ThuderX platform. Including three api to register/unregister ioport misc device - igbuio_ioport_register - igbuio_ioport_unregister - igbuio_iomap Signed-off-by: Santosh Shukla Signed-off-by: Rizwan Ansari Signed-off-by: Rakesh Krishnamurthy --- lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 8 +- .../linuxapp/igb_uio/igbuio_ioport_misc.h | 133 ++++++++++++++++++++ 2 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 lib/librte_eal/linuxapp/igb_uio/igbuio_ioport_misc.h diff --git a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c index f5617d2..155bf39 100644 --- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c +++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c @@ -39,6 +39,7 @@ #include #include "compat.h" +#include "igbuio_ioport_misc.h" #ifdef RTE_PCI_CONFIG #define PCI_SYS_FILE_BUF_SIZE 10 @@ -366,7 +367,7 @@ igbuio_pci_setup_ioport(struct pci_dev *dev, struct uio_info *info, return -EINVAL; info->port[n].name = name; - info->port[n].start = addr; + info->port[n].start = igbuio_iomap(addr); info->port[n].size = len; info->port[n].porttype = UIO_PORT_X86; @@ -615,6 +616,10 @@ igbuio_pci_init_module(void) { int ret; + ret = igbuio_ioport_register(); + if (ret < 0) + return ret; + ret = igbuio_config_intr_mode(intr_mode); if (ret < 0) return ret; @@ -625,6 +630,7 @@ igbuio_pci_init_module(void) static void __exit igbuio_pci_exit_module(void) { + igbuio_ioport_unregister(); pci_unregister_driver(&igbuio_pci_driver); } diff --git a/lib/librte_eal/linuxapp/igb_uio/igbuio_ioport_misc.h b/lib/librte_eal/linuxapp/igb_uio/igbuio_ioport_misc.h new file mode 100644 index 0000000..04e2c28 --- /dev/null +++ b/lib/librte_eal/linuxapp/igb_uio/igbuio_ioport_misc.h @@ -0,0 +1,133 @@ +/*- + * GPL LICENSE SUMMARY + * + * Copyright(c) 2015 Cavium Networks. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Cavium Networks + */ + +#ifndef _IGBUIO_IOPORT_MISC_H_ +#define _IGBUIO_IOPORT_MISC_H_ + +unsigned long igbuio_iomap(unsigned long addr); +int igbuio_ioport_register(void); +void igbuio_ioport_unregister(void); + +#if defined(RTE_ARCH_ARM) || defined(RTE_ARCH_ARM64) +#ifdef CONFIG_HAS_IOPORT_MAP +/* + * mmap driver to map x86-style PCI_IOBAR (i.e..cat /proc/ioport pci-bar-memory) + * from kernel-space virtual address to user-space virtual address. This module + * required for non-x86 archs example arm/arm64, as those archs donot do + * IO_MAP_IO types access, Infact supports memory-mapped-IO. That is because + * arm/arm64 doesn't support direct IO instruction, so the design approach is to + * map `cat /proc/ioport` PCI_IOBAR's kernel-space virtual-addr to user-space + * virtual-addr. Therefore the need for mmap-driver. + */ +#include /* file_operations */ +#include +#include /* VM_IO */ +#include +#include +#include +#include +#include + +void *__iomem mapped_io; /* ioport addr of `cat /proc/ioport` */ + +static int igbuio_ioport_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct page *npage; + int ret = 0; + + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + npage = vmalloc_to_page(mapped_io); + ret = remap_pfn_range(vma, vma->vm_start, + page_to_pfn(npage), + vma->vm_end - vma->vm_start, + vma->vm_page_prot); + if (ret) { + pr_info("Error: Failed to remap pfn=%lu error=%d\n", + page_to_pfn(npage), ret); + } + return 0; +} + +static const struct file_operations igbuio_ioport_fops = { + .mmap = igbuio_ioport_mmap, +}; + +static struct miscdevice igbuio_ioport_dev = { + .minor = MISC_DYNAMIC_MINOR, + .name = "igb_ioport", + .fops = &igbuio_ioport_fops +}; + +unsigned long igbuio_iomap(unsigned long addr) +{ + mapped_io = ioport_map(addr, 0); + return (unsigned long)(uintptr_t)mapped_io; +} + +int igbuio_ioport_register(void) +{ + int ret; + ret = misc_register(&igbuio_ioport_dev); + if (ret < 0) { + pr_info("Error: failed to register ioport map driver (%d)\n", + ret); + return ret; + } + return ret; +} + +void igbuio_ioport_unregister(void) +{ + misc_deregister(&igbuio_ioport_dev); +} + +#else /* !CONFIG_HAS_IOPORT_MAP */ + +#error "CONFIG_HAS_IOPORT_MAP not supported for $RTE_ARCH" + +#endif /* CONFIG_HAS_IOPORT_MAP */ + +#else /* !RTE_ARCH_ARM, !RTE_ARCH_ARM64 */ + +unsigned long igbuio_iomap(unsigned long addr) +{ + /* non-arm case : simply return addr */ + return addr; +} + +int igbuio_ioport_register(void) +{ + /* non-arm case : do nothing */ + return 0; +} + +void igbuio_ioport_unregister(void) +{ + /* non-arm case : do nothing */ + return; +} + +#endif /* RTE_ARCH_ARM , RTE_ARCH_ARM64 */ + +#endif /* _IGBUIO_IOPORT_MISC_H_ */ -- 1.7.9.5