summaryrefslogtreecommitdiffstats
path: root/drivers/vfio/pci/vfio_pci.c
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2013-02-14 14:02:12 -0700
committerAlex Williamson <alex.williamson@redhat.com>2013-02-14 14:02:12 -0700
commit906ee99dd2a5c819c1171ce5eaf6c080c027e58c (patch)
treec89c9d8fdb61d7e2843c28c9c52faaf8e9089917 /drivers/vfio/pci/vfio_pci.c
parent5b279a11d32998aad1e45fe9de225302b6a8e8ba (diff)
downloadlinux-906ee99dd2a5c819c1171ce5eaf6c080c027e58c.tar.bz2
vfio-pci: Cleanup BAR access
We can actually handle MMIO and I/O port from the same access function since PCI already does abstraction of this. The ROM BAR only requires a minor difference, so it gets included too. vfio_pci_config_readwrite gets renamed for consistency. Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio/pci/vfio_pci.c')
-rw-r--r--drivers/vfio/pci/vfio_pci.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 469e110d7ea6..bb8c8c2be960 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -371,31 +371,21 @@ static ssize_t vfio_pci_rw(void *device_data, char __user *buf,
{
unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
struct vfio_pci_device *vdev = device_data;
- struct pci_dev *pdev = vdev->pdev;
if (index >= VFIO_PCI_NUM_REGIONS)
return -EINVAL;
switch (index) {
case VFIO_PCI_CONFIG_REGION_INDEX:
- return vfio_pci_config_readwrite(vdev, buf, count,
- ppos, iswrite);
+ return vfio_pci_config_rw(vdev, buf, count, ppos, iswrite);
+
case VFIO_PCI_ROM_REGION_INDEX:
if (iswrite)
return -EINVAL;
- return vfio_pci_mem_readwrite(vdev, buf, count, ppos, false);
+ return vfio_pci_bar_rw(vdev, buf, count, ppos, false);
case VFIO_PCI_BAR0_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
- {
- unsigned long flags = pci_resource_flags(pdev, index);
-
- if (flags & IORESOURCE_IO)
- return vfio_pci_io_readwrite(vdev, buf, count,
- ppos, iswrite);
- if (flags & IORESOURCE_MEM)
- return vfio_pci_mem_readwrite(vdev, buf, count,
- ppos, iswrite);
- }
+ return vfio_pci_bar_rw(vdev, buf, count, ppos, iswrite);
}
return -EINVAL;
@@ -404,13 +394,19 @@ static ssize_t vfio_pci_rw(void *device_data, char __user *buf,
static ssize_t vfio_pci_read(void *device_data, char __user *buf,
size_t count, loff_t *ppos)
{
+ if (!count)
+ return 0;
+
return vfio_pci_rw(device_data, buf, count, ppos, false);
}
static ssize_t vfio_pci_write(void *device_data, const char __user *buf,
size_t count, loff_t *ppos)
{
- return vfio_pci_rw(device_data, buf, count, ppos, true);
+ if (!count)
+ return 0;
+
+ return vfio_pci_rw(device_data, (char __user *)buf, count, ppos, true);
}
static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)