vfio/pci: Expose vfio_pci_core_setup_barmap()
authorYishai Hadas <yishaih@nvidia.com>
Tue, 19 Dec 2023 09:32:45 +0000 (11:32 +0200)
committerAlex Williamson <alex.williamson@redhat.com>
Tue, 19 Dec 2023 18:51:33 +0000 (11:51 -0700)
Expose vfio_pci_core_setup_barmap() to be used by drivers.

This will let drivers to mmap a BAR and re-use it from both vfio and the
driver when it's applicable.

This API will be used in the next patches by the vfio/virtio coming
driver.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://lore.kernel.org/r/20231219093247.170936-8-yishaih@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/vfio_pci_rdwr.c
include/linux/vfio_pci_core.h

index e27de61ac9fe75f5818dc8d7386270c592c05a07..a9887fd6de46c81da27049f4ee88997ba50758db 100644 (file)
@@ -200,7 +200,7 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
        return done;
 }
 
-static int vfio_pci_setup_barmap(struct vfio_pci_core_device *vdev, int bar)
+int vfio_pci_core_setup_barmap(struct vfio_pci_core_device *vdev, int bar)
 {
        struct pci_dev *pdev = vdev->pdev;
        int ret;
@@ -223,6 +223,7 @@ static int vfio_pci_setup_barmap(struct vfio_pci_core_device *vdev, int bar)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(vfio_pci_core_setup_barmap);
 
 ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
                        size_t count, loff_t *ppos, bool iswrite)
@@ -262,7 +263,7 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
                }
                x_end = end;
        } else {
-               int ret = vfio_pci_setup_barmap(vdev, bar);
+               int ret = vfio_pci_core_setup_barmap(vdev, bar);
                if (ret) {
                        done = ret;
                        goto out;
@@ -438,7 +439,7 @@ int vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset,
                return -EINVAL;
 #endif
 
-       ret = vfio_pci_setup_barmap(vdev, bar);
+       ret = vfio_pci_core_setup_barmap(vdev, bar);
        if (ret)
                return ret;
 
index 562e8754869da6c6a5c46c2dd55b4775c27b0722..67ac58e20e1da3135c28c22913208fc3238fe490 100644 (file)
@@ -127,6 +127,7 @@ int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf);
 int vfio_pci_core_enable(struct vfio_pci_core_device *vdev);
 void vfio_pci_core_disable(struct vfio_pci_core_device *vdev);
 void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev);
+int vfio_pci_core_setup_barmap(struct vfio_pci_core_device *vdev, int bar);
 pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev,
                                                pci_channel_state_t state);