[dpdk-dev,v5,05/11] eal: pci: vfio: add rd/wr func for pci bar space
Commit Message
Introducing below api for pci bar space rd/wr. Currently used for
pci iobar rd/wr.
Api's are:
- rte_eal_pci_read_bar
- rte_eal_pci_write_bar
virtio when used for vfio-mode then virtio driver will use these api
to do rd/wr operation on ioport pci bar.
Signed-off-by: Santosh Shukla <sshukla@mvista.com>
---
v4--> v5:
- added switch case in rd/wr pci_bar routine, as per Yuan comment
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 ++++++++++++++++++++
4 files changed, 106 insertions(+)
Comments
Santosh,
On Tue, Jan 19, 2016 at 12:46 PM, Santosh Shukla <sshukla@mvista.com> wrote:
> Introducing below api for pci bar space rd/wr. Currently used for
> pci iobar rd/wr.
>
> Api's are:
> - rte_eal_pci_read_bar
> - rte_eal_pci_write_bar
>
> virtio when used for vfio-mode then virtio driver will use these api
> to do rd/wr operation on ioport pci bar.
>
> Signed-off-by: Santosh Shukla <sshukla@mvista.com>
> ---
> v4--> v5:
> - added switch case in rd/wr pci_bar routine, as per Yuan comment
>
> 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 ++++++++++++++++++++
> 4 files changed, 106 insertions(+)
- What about BSD ?
Empty stub ?
- Those are new symbols, you must update rte_eal_version.map.
Regards,
On Thu, Jan 21, 2016 at 3:12 PM, David Marchand
<david.marchand@6wind.com> wrote:
> Santosh,
>
> On Tue, Jan 19, 2016 at 12:46 PM, Santosh Shukla <sshukla@mvista.com> wrote:
>> Introducing below api for pci bar space rd/wr. Currently used for
>> pci iobar rd/wr.
>>
>> Api's are:
>> - rte_eal_pci_read_bar
>> - rte_eal_pci_write_bar
>>
>> virtio when used for vfio-mode then virtio driver will use these api
>> to do rd/wr operation on ioport pci bar.
>>
>> Signed-off-by: Santosh Shukla <sshukla@mvista.com>
>> ---
>> v4--> v5:
>> - added switch case in rd/wr pci_bar routine, as per Yuan comment
>>
>> 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 ++++++++++++++++++++
>> 4 files changed, 106 insertions(+)
>
> - What about BSD ?
> Empty stub ?
>
> - Those are new symbols, you must update rte_eal_version.map.
>
>
for both, agreed. Sending v6 for this patch now, Thanks!
> Regards,
> --
> David Marchand
@@ -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
@@ -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)
@@ -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);
@@ -93,6 +93,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,