From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: Santosh Shukla <sshukla@mvista.com>
Cc: dev@dpdk.org, Rakesh Krishnamurthy <rakeshk@mvista.com>,
Rizwan Ansari <ransari@mvista.com>
Subject: Re: [dpdk-dev] [ [PATCH v2] 11/13] virtio_ioport: armv7/v8: mmap virtio iopci bar region
Date: Wed, 16 Dec 2015 21:29:40 +0800 [thread overview]
Message-ID: <20151216132940.GT29571@yliu-dev.sh.intel.com> (raw)
In-Reply-To: <1450098032-21198-12-git-send-email-sshukla@mvista.com>
On Mon, Dec 14, 2015 at 06:30:30PM +0530, Santosh Shukla wrote:
> Introducing module to mmap iopci bar region. Applicable for linuxapp for non-x86
> archs, Tested for arm64/ThunderX platform for linux. For that adding two global
> api.
> - virtio_ioport_init
> - virtio_ioport_unmap
>
> Signed-off-by: Santosh Shukla <sshukla@mvista.com>
> Signed-off-by: Rizwan Ansari <ransari@mvista.com>
> Signed-off-by: Rakesh Krishnamurthy <rakeshk@mvista.com>
> ---
> drivers/net/virtio/Makefile | 1 +
> drivers/net/virtio/virtio_ioport.c | 163 ++++++++++++++++++++++++++++++++++++
> drivers/net/virtio/virtio_ioport.h | 42 ++++++++++
> 3 files changed, 206 insertions(+)
> create mode 100644 drivers/net/virtio/virtio_ioport.c
> create mode 100644 drivers/net/virtio/virtio_ioport.h
>
> diff --git a/drivers/net/virtio/Makefile b/drivers/net/virtio/Makefile
> index 25a842d..5cba6d3 100644
> --- a/drivers/net/virtio/Makefile
> +++ b/drivers/net/virtio/Makefile
> @@ -50,6 +50,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtqueue.c
> SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_pci.c
> SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx.c
> SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_ethdev.c
> +SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_ioport.c
> SRCS-$(CONFIG_RTE_VIRTIO_INC_VECTOR) += virtio_rxtx_simple.c
>
> # this lib depends upon:
> diff --git a/drivers/net/virtio/virtio_ioport.c b/drivers/net/virtio/virtio_ioport.c
> new file mode 100644
> index 0000000..ffeb8e9
> --- /dev/null
> +++ b/drivers/net/virtio/virtio_ioport.c
> @@ -0,0 +1,163 @@
> +/*
> + * BSD LICENSE
> + *
> + * Copyright(c) 2015 Cavium Networks. All rights reserved.
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * * Redistributions of source code must retain the above copyright
> + * notice, this list of conditions and the following disclaimer.
> + * * Redistributions in binary form must reproduce the above copyright
> + * notice, this list of conditions and the following disclaimer in
> + * the documentation and/or other materials provided with the
> + * distribution.
> + * * Neither the name of Intel Corporation nor the names of its
> + * contributors may be used to endorse or promote products derived
> + * from this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + *
> + */
> +
> +#include "virtio_ioport.h"
> +
> +#if defined(RTE_EXEC_ENV_LINUXAPP) && (defined(RTE_ARCH_ARM) || \
> + defined(RTE_ARCH_ARM64))
> +
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +#include <errno.h>
> +#include <unistd.h>
> +#include <sys/mman.h>
> +#include <exec-env/rte_virt_ioport.h>
> +
> +#include "virtio_logs.h"
> +
> +/* start address of first pci_iobar slot (user-space virtual-addres) */
> +void *ioport_map;
You still forgot "static"?
> +/**
> + * ioport map count,
> + * Use-case: virtio-net-pci.
How about removing above two lines; it's quite meaningless here, but
instead a bit redundant.
> + * Keeps track of number of virtio-net-pci device mapped/unmapped. Max device
> + * support by linux kernel is 31, so ioport_map_cnt can not be greater than 31.
> + */
> +static int ioport_map_cnt;
> +
> +static int
> +virtio_map_ioport(void **resource_addr)
> +{
> + int fd;
> + int ret = 0;
> +
> + /* avoid -Werror=unused-parameter, keep compiler happy */
> + (void)resource_addr;
Using __rte_unused is more elegant.
> + fd = open(VIRT_IOPORT_DEV, O_RDWR);
> + if (fd < 0) {
> + PMD_INIT_LOG(ERR, "device file %s open error: %d\n",
> + DEV_NAME, fd);
> + ret = -1;
> + goto out;
> + }
> +
> + ioport_map = mmap(NULL, PCI_VIRT_IOPORT_SIZE,
> + PROT_EXEC | PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
> +
> + if (ioport_map == MAP_FAILED) {
> + PMD_INIT_LOG(ERR, "mmap: failed to map bar Address=%p\n",
> + *resource_addr);
> + ret = -ENOMEM;
> + goto out1;
> + }
> +
> + PMD_INIT_LOG(INFO, "First pci_iobar mapped at %p\n", ioport_map);
> +
> +out1:
> + close(fd);
> +out:
> + return ret;
> +}
> +
> +static int
> +virtio_set_ioport_addr(void **resource_addr, unsigned long offset)
> +{
> + int ret = 0;
> +
> + if (ioport_map_cnt >= PCI_VIRT_IOPORT_MAX) {
> + ret = -1;
> + PMD_INIT_LOG(ERR,
> + "ioport_map_cnt(%d) greater than"
> + "PCI_VIRT_IOPORT_MAX(%d)\n",
> + ioport_map_cnt, PCI_VIRT_IOPORT_MAX);
> + return ret;
> + }
> + *resource_addr = (void *)((char *)ioport_map + (ioport_map_cnt)*offset);
Redundant (), and the void * cast seems to be unnecessary.
> + ioport_map_cnt++;
> +
> + PMD_INIT_LOG(DEBUG, "pci.resource_addr %p ioport_map_cnt %d\n",
> + *resource_addr, ioport_map_cnt);
> + return ret;
> +}
> +
> +int virtio_ioport_init(struct rte_pci_resource *mem_resource)
> +{
> + int ret = 0;
> +
> + /**
> + * Map the all IOBAR entry from /proc/ioport to 4k page_size only once.
> + * Later virtio_set_ioport_addr() func will update correct bar_addr for
> + * each ioport (i.e..pci_dev->mem_resource[0].addr)
> + */
> + if (!ioport_map) {
> + ret = virtio_map_ioport(&mem_resource->addr);
> + if (ret < 0)
> + return ret;
> + PMD_INIT_LOG(INFO, "ioport_map %p\n", ioport_map);
> + }
> +
> + ret = virtio_set_ioport_addr(&mem_resource->addr, mem_resource->len);
> + if (ret < 0)
> + return ret;
> +
> + PMD_INIT_LOG(INFO, "resource_addr %p resource_len :%ld\n",
> + mem_resource->addr, (unsigned long)mem_resource->len);
> + return ret;
> +}
> +
> +void virtio_ioport_unmap(void)
> +{
> + /* unmap ioport memory */
Redundant comment.
> + ioport_map_cnt--;
> + if (!ioport_map_cnt)
> + munmap(ioport_map, PCI_VIRT_IOPORT_SIZE);
> +
> + PMD_INIT_LOG(DEBUG, "unmapping ioport_mem %d\n", ioport_map_cnt);
> +}
> +
> +#else /* !LINUXAPP && !ARM/64 */
> +
> +int virtio_ioport_init(struct rte_pci_resource *mem_resource)
> +{
> + (void)mem_resource;
ditto.
> + return 0;
> +}
> +
> +void virtio_ioport_unmap(void)
> +{
> + return;
> +}
> +
> +#endif /* LINUXAPP, ARM/64 */
> diff --git a/drivers/net/virtio/virtio_ioport.h b/drivers/net/virtio/virtio_ioport.h
> new file mode 100644
> index 0000000..bf79551
> --- /dev/null
> +++ b/drivers/net/virtio/virtio_ioport.h
> @@ -0,0 +1,42 @@
> +/*
> + * BSD LICENSE
> + *
> + * Copyright(c) 2015 Cavium Networks. All rights reserved.
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * * Redistributions of source code must retain the above copyright
> + * notice, this list of conditions and the following disclaimer.
> + * * Redistributions in binary form must reproduce the above copyright
> + * notice, this list of conditions and the following disclaimer in
> + * the documentation and/or other materials provided with the
> + * distribution.
> + * * Neither the name of Intel Corporation nor the names of its
> + * contributors may be used to endorse or promote products derived
> + * from this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + *
> + */
> +#ifndef _VIRTIO_IOPORT_H_
> +#define _VIRTIO_IOPORT_H_
> +
> +#include <rte_pci.h>
> +
> +int virtio_ioport_init(struct rte_pci_resource *mem_resource);
> +void virtio_ioport_unmap(void);
> +
> +#endif /* _VIRTIO_IOPORT_H_ */
> --
> 1.7.9.5
next prev parent reply other threads:[~2015-12-16 13:29 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-14 13:00 [dpdk-dev] [ [PATCH v2] 00/13] Add virtio support in arm/arm64 Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 01/13] virtio: Introduce config RTE_VIRTIO_INC_VECTOR Santosh Shukla
2015-12-17 12:02 ` Santosh Shukla
2015-12-17 12:03 ` Thomas Monjalon
2015-12-17 12:18 ` Santosh Shukla
2015-12-17 23:24 ` Stephen Hemminger
2015-12-18 1:31 ` Yuanhan Liu
2015-12-18 9:52 ` Xie, Huawei
2015-12-18 10:41 ` Thomas Monjalon
2015-12-18 17:33 ` Stephen Hemminger
2015-12-18 18:11 ` Thomas Monjalon
2015-12-18 12:46 ` Santosh Shukla
2015-12-22 6:26 ` Yuanhan Liu
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 02/13] config: i686: set RTE_VIRTIO_INC_VECTOR=n Santosh Shukla
2015-12-17 12:03 ` Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 03/13] rte_io: armv7/v8: Introduce api to emulate x86-style of PCI/ISA ioport access Santosh Shukla
2015-12-14 14:25 ` Jerin Jacob
2015-12-14 16:29 ` Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 04/13] virtio_pci: use rte_io.h for non-x86 arch Santosh Shukla
2015-12-14 14:28 ` Jerin Jacob
2015-12-14 15:29 ` Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 05/13] virtio: change io_base datatype from uint32_t to uint64_type Santosh Shukla
2015-12-16 13:48 ` Yuanhan Liu
2015-12-16 14:01 ` Santosh Shukla
2015-12-16 14:23 ` Yuanhan Liu
2015-12-16 14:39 ` Santosh Shukla
2015-12-16 14:58 ` Yuanhan Liu
2015-12-16 15:05 ` Santosh Shukla
2015-12-17 7:19 ` Yuanhan Liu
2015-12-17 8:17 ` Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 06/13] config: armv7/v8: Enable RTE_LIBRTE_VIRTIO_PMD Santosh Shukla
2015-12-14 14:31 ` Jerin Jacob
2015-12-14 16:16 ` Santosh Shukla
2015-12-15 5:36 ` Jianbo Liu
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 07/13] linuxapp: eal: arm: Always return 0 for rte_eal_iopl_init() Santosh Shukla
2015-12-14 14:34 ` Jan Viktorin
2015-12-14 15:04 ` Santosh Shukla
2015-12-14 14:37 ` Jerin Jacob
2015-12-14 15:24 ` Santosh Shukla
2015-12-14 15:56 ` Jerin Jacob
2015-12-14 16:13 ` Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 08/13] rte_io: x86: Remove sys/io.h ifdef x86 clutter Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 09/13] igb_uio: ioport: map iopci region for armv7/v8 Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 10/13] include/exec-env: ioport: add rte_virt_ioport header file Santosh Shukla
2015-12-14 14:43 ` Jerin Jacob
2015-12-14 16:17 ` Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 11/13] virtio_ioport: armv7/v8: mmap virtio iopci bar region Santosh Shukla
2015-12-16 13:29 ` Yuanhan Liu [this message]
2015-12-16 14:20 ` Santosh Shukla
2015-12-16 14:37 ` Yuanhan Liu
2015-12-16 14:40 ` Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 12/13] virtio_ethdev: use virtio_ioport api at device init/close Santosh Shukla
2015-12-14 13:00 ` [dpdk-dev] [ [PATCH v2] 13/13] virtio_ethdev : fix format specifier error for 64bit addr case Santosh Shukla
2015-12-14 14:31 ` [dpdk-dev] [ [PATCH v2] 00/13] Add virtio support in arm/arm64 Jan Viktorin
2015-12-14 16:09 ` Santosh Shukla
2015-12-16 7:48 ` Santosh Shukla
2015-12-16 8:47 ` David Marchand
2015-12-16 11:43 ` Santosh Shukla
2015-12-16 12:31 ` [dpdk-dev] [PATCH] eal: map io resources for non x86 architectures David Marchand
2015-12-16 12:48 ` Yuanhan Liu
2015-12-16 13:34 ` David Marchand
2015-12-16 13:42 ` Yuanhan Liu
2015-12-16 13:51 ` Santosh Shukla
2015-12-17 9:38 ` Yuanhan Liu
2015-12-17 10:01 ` Santosh Shukla
2015-12-17 10:02 ` Santosh Shukla
2015-12-17 10:07 ` Santosh Shukla
2015-12-17 10:14 ` Thomas Monjalon
2015-12-17 10:21 ` Santosh Shukla
2015-12-17 10:33 ` Thomas Monjalon
2015-12-17 11:22 ` Santosh Shukla
2015-12-18 5:30 ` Yuanhan Liu
2015-12-18 6:34 ` Jerin Jacob
2015-12-18 7:55 ` Yuanhan Liu
2015-12-18 9:37 ` Thomas Monjalon
2015-12-18 7:54 ` Santosh Shukla
2015-12-18 8:21 ` Yuanhan Liu
2015-12-18 12:55 ` Santosh Shukla
2015-12-29 5:56 ` Santosh Shukla
2015-12-29 9:56 ` Burakov, Anatoly
2015-12-29 10:47 ` Santosh Shukla
2015-12-29 11:06 ` Burakov, Anatoly
2015-12-29 12:23 ` Santosh Shukla
2015-12-29 14:04 ` Alex Williamson
2015-12-29 14:51 ` Santosh Shukla
2015-12-31 14:27 ` Santosh Shukla
2015-12-16 13:15 ` Bruce Richardson
2015-12-16 13:29 ` David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151216132940.GT29571@yliu-dev.sh.intel.com \
--to=yuanhan.liu@linux.intel.com \
--cc=dev@dpdk.org \
--cc=rakeshk@mvista.com \
--cc=ransari@mvista.com \
--cc=sshukla@mvista.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).