From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by dpdk.org (Postfix) with ESMTP id 1DEA9C74C for ; Fri, 29 Jan 2016 19:22:38 +0100 (CET) Received: by mail-pa0-f44.google.com with SMTP id uo6so45909812pac.1 for ; Fri, 29 Jan 2016 10:22:38 -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=5cw8L6f9BMYKdm8HqFytcFQ+WamBBV3sBgnC02E6LGY=; b=Hj2ygMvCEibieXIU6qGwfxdvS+jMKnKdGCr2aTywRSJHUfrDcyesqjd4lzCOE01oxc gNAATYriCAZs4yRzen6K8XZBax7YY06llAodp56S0d3yvTC+r/CdtoLK5SPTUpUZyb7o /GRxyUSt2/RKbd+PCv/i69pLGSNUZongLBhC+8lRyBwFkQZtngzQP1MwC1RmmtkxrOj/ xv2CKisz/woI83aFuEvaC6a3GFfPAjExq4zEpN7pSonblkZe2ZZZO1NzB7LIugBWrvQL 7Vhwl/Zz5Bo3IxmMtzfDOYl3Bkp/1iAr4av1stwjm6b4OTHv9poyos8YqP8zOUSSYciW 2H0w== 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=5cw8L6f9BMYKdm8HqFytcFQ+WamBBV3sBgnC02E6LGY=; b=fsA1XWSy+cV0oV9DGBYPWJ7xTo4BQo/7HVZtALIJ11U3nMxRGbmg49BJhqw77mYjYA edSg5a62KAdMILf/MW+/QTwtKdUgEEFFpfa0DtBbVMtsbCV08104xqSCVcULHbv0r+gs FBOFkvVUJX0n0+efpikmgAscDira1+5aQweFzhiDYjGZbO6m8cfJbuXWvgAwAToZKFZd GKPkKWs+RpXtK24S7+rwh1PJ4SB5nYo5J+mGcczmDqawRoagmL3G03KUm2jGFnUeAp8n OMOmgX6DrifIhtyJ9tsMs77cuaTmAVkCSMp1/Ku3i8vYiHpK0fLll7r+YfxQ1gTp6D7e cqTA== X-Gm-Message-State: AG10YOSK6lvRUCiRV7tH7Ojd05mKOnMekIXLrmo+Ha+e/T0ViHQ2j8gp/S9mP7x9RUL2cEj3 X-Received: by 10.66.197.131 with SMTP id iu3mr15563929pac.57.1454091757499; Fri, 29 Jan 2016 10:22:37 -0800 (PST) Received: from santosh-Latitude-E5530-non-vPro.mvista.com ([106.51.29.23]) by smtp.gmail.com with ESMTPSA id 85sm11161750pfl.18.2016.01.29.10.22.22 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jan 2016 10:22:36 -0800 (PST) From: Santosh Shukla To: dev@dpdk.org Date: Fri, 29 Jan 2016 23:51:50 +0530 Message-Id: <1454091717-32251-1-git-send-email-sshukla@mvista.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <0000-cover-letter.patch> References: <0000-cover-letter.patch> Subject: [dpdk-dev] [PATCH v6 1/8] eal: pci: add api to rd/wr pci bar region 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: Fri, 29 Jan 2016 18:22:38 -0000 Introducing below api for pci bar region rd/wr. Api's are: - rte_eal_pci_read_bar - rte_eal_pci_write_bar Signed-off-by: Santosh Shukla --- v5-->v6: - update api infor in rte_eal_version.map file suggested by david manchand. lib/librte_eal/bsdapp/eal/eal_pci.c | 19 ++++++++++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 3 ++ lib/librte_eal/common/include/rte_pci.h | 38 +++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 34 ++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci_init.h | 6 ++++ lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 28 +++++++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 3 ++ 7 files changed, 131 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 95c32c1..2e535ea 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -479,6 +479,25 @@ int rte_eal_pci_write_config(const struct rte_pci_device *dev, return -1; } +int rte_eal_pci_read_bar(const struct rte_pci_device *device __rte_unused, + void *buf __rte_unused, size_t len __rte_unused, + off_t offset __rte_unused, + int bar_idx __rte_unused) + +{ + /* NA */ + return 1; +} + +int rte_eal_pci_write_bar(const struct rte_pci_device *device __rte_unused, + const void *buf __rte_unused, size_t len __rte_unused, + off_t offset __rte_unused, + int bar_idx __rte_unused) +{ + /* NA */ + return 1; +} + /* Init the PCI EAL subsystem */ int rte_eal_pci_init(void) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 1b28170..7c7dcf0 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -141,4 +141,7 @@ DPDK_2.3 { rte_eal_pci_map_device; rte_eal_pci_unmap_device; + rte_eal_pci_read_bar; + rte_eal_pci_write_bar; + } DPDK_2.2; diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 2224109..0c667ff 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -471,6 +471,44 @@ int rte_eal_pci_read_config(const struct rte_pci_device *device, void *buf, size_t len, off_t offset); /** + * Read PCI bar space. + * + * @param device + * A pointer to a rte_pci_device structure describing the device + * to use + * @param buf + * A data buffer where the bytes should be read into + * @param len + * The length of the data buffer. + * @param offset + * The offset into PCI bar space + * @param bar_idx + * The pci bar index (valid range is 0..5) + */ +int rte_eal_pci_read_bar(const struct rte_pci_device *device, + void *buf, size_t len, off_t offset, int bar_idx); + +/** + * Write PCI bar space. + * + * @param device + * A pointer to a rte_pci_device structure describing the device + * to use + * @param buf + * A data buffer containing the bytes should be written + * @param len + * The length of the data buffer. + * @param offset + * The offset into PCI config space + * @param bar_idx + * The pci bar index (valid range is 0..5) +*/ +int rte_eal_pci_write_bar(const struct rte_pci_device *device, + const void *buf, size_t len, off_t offset, + int bar_idx); + + +/** * Write PCI config space. * * @param device diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index db947da..eb503f0 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -621,6 +621,40 @@ int rte_eal_pci_write_config(const struct rte_pci_device *device, } } +int rte_eal_pci_read_bar(const struct rte_pci_device *device, + void *buf, size_t len, off_t offset, + int bar_idx) + +{ + const struct rte_intr_handle *intr_handle = &device->intr_handle; + + switch (device->kdrv) { + case RTE_KDRV_VFIO: + return pci_vfio_read_bar(intr_handle, buf, len, + offset, bar_idx); + default: + RTE_LOG(ERR, EAL, "write bar not supported by driver\n"); + return -1; + } +} + +int rte_eal_pci_write_bar(const struct rte_pci_device *device, + const void *buf, size_t len, off_t offset, + int bar_idx) +{ + + const struct rte_intr_handle *intr_handle = &device->intr_handle; + + switch (device->kdrv) { + case RTE_KDRV_VFIO: + return pci_vfio_write_bar(intr_handle, buf, len, + offset, bar_idx); + default: + RTE_LOG(ERR, EAL, "write bar not supported by driver\n"); + return -1; + } +} + /* Init the PCI EAL subsystem */ int rte_eal_pci_init(void) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h index a17c708..3bc592b 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h @@ -68,6 +68,12 @@ int pci_vfio_read_config(const struct rte_intr_handle *intr_handle, int pci_vfio_write_config(const struct rte_intr_handle *intr_handle, const void *buf, size_t len, off_t offs); +int pci_vfio_read_bar(const struct rte_intr_handle *intr_handle, + void *buf, size_t len, off_t offs, int bar_idx); + +int pci_vfio_write_bar(const struct rte_intr_handle *intr_handle, + const void *buf, size_t len, off_t offs, int bar_idx); + /* map VFIO resource prototype */ int pci_vfio_map_resource(struct rte_pci_device *dev); int pci_vfio_get_group_fd(int iommu_group_fd); diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index a6c7e16..34c4558 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -156,6 +156,34 @@ pci_vfio_write_config(const struct rte_intr_handle *intr_handle, VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) + offs); } +int +pci_vfio_read_bar(const struct rte_intr_handle *intr_handle, + void *buf, size_t len, off_t offs, int bar_idx) +{ + if (bar_idx < VFIO_PCI_BAR0_REGION_INDEX + || bar_idx > VFIO_PCI_BAR5_REGION_INDEX) { + RTE_LOG(ERR, EAL, "invalid bar_idx!\n"); + return -1; + } + + return pread64(intr_handle->vfio_dev_fd, buf, len, + VFIO_GET_REGION_ADDR(bar_idx) + offs); +} + +int +pci_vfio_write_bar(const struct rte_intr_handle *intr_handle, + const void *buf, size_t len, off_t offs, int bar_idx) +{ + if (bar_idx < VFIO_PCI_BAR0_REGION_INDEX + || bar_idx > VFIO_PCI_BAR5_REGION_INDEX) { + RTE_LOG(ERR, EAL, "invalid bar_idx!\n"); + return -1; + } + + return pwrite64(intr_handle->vfio_dev_fd, buf, len, + VFIO_GET_REGION_ADDR(bar_idx) + offs); +} + /* get PCI BAR number where MSI-X interrupts are */ static int pci_vfio_get_msix_bar(int fd, int *msix_bar, uint32_t *msix_table_offset, diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index b9937c4..371b6c1 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -144,4 +144,7 @@ DPDK_2.3 { rte_eal_pci_map_device; rte_eal_pci_unmap_device; + rte_eal_pci_read_bar; + rte_eal_pci_write_bar; + } DPDK_2.2; -- 1.7.9.5