From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f181.google.com (mail-pf0-f181.google.com [209.85.192.181]) by dpdk.org (Postfix) with ESMTP id 4E1E38DAC for ; Mon, 8 Feb 2016 11:05:20 +0100 (CET) Received: by mail-pf0-f181.google.com with SMTP id o185so107363428pfb.1 for ; Mon, 08 Feb 2016 02:05:20 -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=c4t+KavpuhtZx5DNxUbMs2Dwg4MbHdM2Me5OJmg9YsE=; b=dEKjVlIgwfrC9bCsBEwv3o57QpKWVNy3m/8NOMGpyT7n33RmEsUe1CDlnauZH1AULu K27g1G8UbNbTVA5upAykAohv7Yz9weBWrQp5A3PUQuPMmp9/l5vGldrvhBKgjJBg+m+i wb+BfZ327K139hnr7LfoGd0VDVCjDA0PmJ2VLGPN7RQaSew5KzqfdmXzPWqRgOfA+Q8b LX++7IFSbKLz+jWnas7I/oR2i/tnHYRFy6lwo3sufDwfa/6OH4O8aV2LLhl20enkbBrM yCQ7jnXPQswYvJ9DOHQo79/p7nSu5gN7q9dz50p64juCPK2/Gl7shlf3fsnXLPlGyvQi Se0Q== 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=c4t+KavpuhtZx5DNxUbMs2Dwg4MbHdM2Me5OJmg9YsE=; b=U6jN8sX19ZlnvKawI/uKz4mQRcT2wgQWkGAS3LHyhWb5Q7xgDKNIgrT3RjB9rBqakQ X+4j0I69LzUjNo2H2s+OjXeJlRGkHRoXezDdwKNNHMxGg2zrIq6kh07z5DsxN7xXvWFj p/PJ0zJvu0tekRRPUdt9eUlNZh8xMnGPU46C1wNjd3GYh2EPoNufSYm2eqlORU9yptJj xFOvbwdKKc4HZ8zDTDJLZXGm/NSSDAsyAfGCwn9fG0PyMQ2mv0keFds618H+rgZen3s7 C9w0Jc1NapHo5rSz4/qllcQN9AI2fSXBmv/jWqQRAIgwwlGEEFKM/r59unkohxwojn9S Yw/A== X-Gm-Message-State: AG10YOT+OaSXkGoKKnBQbFx8P53Bu2j3IdUL8gVDXVdWt2FKY8fGEt64bDiJqM7z7Q6omwBQ X-Received: by 10.98.9.219 with SMTP id 88mr36259903pfj.0.1454925919762; Mon, 08 Feb 2016 02:05:19 -0800 (PST) Received: from santosh-Latitude-E5530-non-vPro.mvista.com ([110.172.16.133]) by smtp.gmail.com with ESMTPSA id r26sm42183314pfb.21.2016.02.08.02.05.16 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Feb 2016 02:05:18 -0800 (PST) From: Santosh Shukla To: dev@dpdk.org Date: Mon, 8 Feb 2016 15:33:35 +0530 Message-Id: <1454925815-14292-2-git-send-email-sshukla@mvista.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1454925815-14292-1-git-send-email-sshukla@mvista.com> References: <0000-cover-letter.patch> <1454925815-14292-1-git-send-email-sshukla@mvista.com> Subject: [dpdk-dev] [PATCH v8 4/4] eal/linux: vfio: add pci ioport support 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, 08 Feb 2016 10:05:20 -0000 Include vfio map/rd/wr support for pci ioport. Signed-off-by: Santosh Shukla --- v7->v8: - Remove rte_pci_ioport malloc and rte_free()/unmap() func from v7. - removed umap from git header. lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 36 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index 4832313..9571ed8 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -74,6 +74,7 @@ EAL_REGISTER_TAILQ(rte_vfio_tailq) #define VFIO_GROUP_FMT "/dev/vfio/%u" #define VFIO_NOIOMMU_GROUP_FMT "/dev/vfio/noiommu-%u" #define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL) +#define VFIO_GET_REGION_IDX(x) (x >> 40) /* per-process VFIO config */ static struct vfio_config vfio_cfg; @@ -999,30 +1000,41 @@ int pci_vfio_ioport_map(struct rte_pci_device *dev, int bar, struct rte_pci_ioport *p) { - RTE_SET_USED(dev); - RTE_SET_USED(bar); - RTE_SET_USED(p); - return -1; + if (bar < VFIO_PCI_BAR0_REGION_INDEX || + bar > VFIO_PCI_BAR5_REGION_INDEX) { + RTE_LOG(ERR, EAL, "invalid bar (%d)!\n", bar); + return -1; + } + + p->dev = dev; + p->offset = VFIO_GET_REGION_ADDR(bar); + return 0; } void pci_vfio_ioport_read(struct rte_pci_ioport *p, void *data, size_t len, off_t offset) { - RTE_SET_USED(p); - RTE_SET_USED(data); - RTE_SET_USED(len); - RTE_SET_USED(offset); + const struct rte_intr_handle *intr_handle = &p->dev->intr_handle; + + if (pread64(intr_handle->vfio_dev_fd, data, + len, p->offset + offset) <= 0) + RTE_LOG(ERR, EAL, + "Can't read from PCI bar (%" PRIu64 ") : offset (%x)\n", + VFIO_GET_REGION_IDX(p->offset), (int)offset); } void pci_vfio_ioport_write(struct rte_pci_ioport *p, const void *data, size_t len, off_t offset) { - RTE_SET_USED(p); - RTE_SET_USED(data); - RTE_SET_USED(len); - RTE_SET_USED(offset); + const struct rte_intr_handle *intr_handle = &p->dev->intr_handle; + + if (pwrite64(intr_handle->vfio_dev_fd, data, + len, p->offset + offset) <= 0) + RTE_LOG(ERR, EAL, + "Can't write to PCI bar (%" PRIu64 ") : offset (%x)\n", + VFIO_GET_REGION_IDX(p->offset), (int)offset); } int -- 1.7.9.5