From: Max Gurtovoy <mgurtovoy@nvidia.com>
To: <alex.williamson@redhat.com>, <cohuck@redhat.com>,
<kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<jgg@nvidia.com>
Cc: <aviadye@nvidia.com>, <oren@nvidia.com>, <shahafs@nvidia.com>,
<parav@nvidia.com>, <artemp@nvidia.com>, <kwankhede@nvidia.com>,
<ACurrid@nvidia.com>, <cjia@nvidia.com>, <yishaih@nvidia.com>,
<kevin.tian@intel.com>, <hch@infradead.org>,
<targupta@nvidia.com>, <shameerali.kolothum.thodi@huawei.com>,
<liulongfang@huawei.com>, <yan.y.zhao@intel.com>,
Max Gurtovoy <mgurtovoy@nvidia.com>
Subject: [PATCH 07/11] vfio-pci: move igd initialization to vfio_pci.c
Date: Thu, 3 Jun 2021 19:08:05 +0300 [thread overview]
Message-ID: <20210603160809.15845-8-mgurtovoy@nvidia.com> (raw)
In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com>
This is a preparation before splitting vfio_pci.ko to 2 drivers. Move
the vendor specific igd initialization from the core part to pci_driver
part.
Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
---
drivers/vfio/pci/vfio_pci.c | 31 ++++++++++++++++++++-
drivers/vfio/pci/vfio_pci_core.c | 46 +++++++++++---------------------
drivers/vfio/pci/vfio_pci_core.h | 8 ++++++
3 files changed, 54 insertions(+), 31 deletions(-)
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 23a21ecbc674..850ea3a94e28 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -83,9 +83,38 @@ static bool vfio_pci_is_denylisted(struct pci_dev *pdev)
return true;
}
+static int vfio_pci_open(struct vfio_device *core_vdev)
+{
+ struct vfio_pci_core_device *vdev =
+ container_of(core_vdev, struct vfio_pci_core_device, vdev);
+ struct pci_dev *pdev = vdev->pdev;
+ int ret;
+
+ lockdep_assert_held(&core_vdev->reflck->lock);
+
+ ret = vfio_pci_core_enable(vdev);
+ if (ret)
+ return ret;
+
+ if (vfio_pci_is_vga(pdev) &&
+ pdev->vendor == PCI_VENDOR_ID_INTEL &&
+ IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
+ ret = vfio_pci_igd_init(vdev);
+ if (ret && ret != -ENODEV) {
+ pci_warn(pdev, "Failed to setup Intel IGD regions\n");
+ vfio_pci_core_disable(vdev);
+ return ret;
+ }
+ }
+
+ vfio_pci_core_finish_enable(vdev);
+
+ return 0;
+}
+
static const struct vfio_device_ops vfio_pci_ops = {
.name = "vfio-pci",
- .open = vfio_pci_core_open,
+ .open = vfio_pci_open,
.release = vfio_pci_core_release,
.ioctl = vfio_pci_core_ioctl,
.read = vfio_pci_core_read,
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 12d5392c78cc..39a3f18bbc08 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -91,11 +91,6 @@ static unsigned int vfio_pci_set_vga_decode(void *opaque, bool single_vga)
return decodes;
}
-static inline bool vfio_pci_is_vga(struct pci_dev *pdev)
-{
- return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
-}
-
static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev)
{
struct resource *res;
@@ -165,7 +160,6 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev)
}
static void vfio_pci_try_bus_reset(struct vfio_pci_core_device *vdev);
-static void vfio_pci_disable(struct vfio_pci_core_device *vdev);
static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data);
/*
@@ -250,7 +244,7 @@ int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, pci_power_t stat
return ret;
}
-static int vfio_pci_enable(struct vfio_pci_core_device *vdev)
+int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
{
struct pci_dev *pdev = vdev->pdev;
int ret;
@@ -319,26 +313,11 @@ static int vfio_pci_enable(struct vfio_pci_core_device *vdev)
if (!vfio_vga_disabled() && vfio_pci_is_vga(pdev))
vdev->has_vga = true;
- if (vfio_pci_is_vga(pdev) &&
- pdev->vendor == PCI_VENDOR_ID_INTEL &&
- IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
- ret = vfio_pci_igd_init(vdev);
- if (ret && ret != -ENODEV) {
- pci_warn(pdev, "Failed to setup Intel IGD regions\n");
- goto disable_exit;
- }
- }
-
- vfio_pci_probe_mmaps(vdev);
return 0;
-
-disable_exit:
- vfio_pci_disable(vdev);
- return ret;
}
-static void vfio_pci_disable(struct vfio_pci_core_device *vdev)
+void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
{
struct pci_dev *pdev = vdev->pdev;
struct vfio_pci_dummy_resource *dummy_res, *tmp;
@@ -481,7 +460,7 @@ void vfio_pci_core_release(struct vfio_device *core_vdev)
vfio_pci_vf_token_user_add(vdev, -1);
vfio_spapr_pci_eeh_release(vdev->pdev);
- vfio_pci_disable(vdev);
+ vfio_pci_core_disable(vdev);
mutex_lock(&vdev->igate);
if (vdev->err_trigger) {
@@ -495,6 +474,13 @@ void vfio_pci_core_release(struct vfio_device *core_vdev)
mutex_unlock(&vdev->igate);
}
+void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev)
+{
+ vfio_pci_probe_mmaps(vdev);
+ vfio_spapr_pci_eeh_open(vdev->pdev);
+ vfio_pci_vf_token_user_add(vdev, 1);
+}
+
int vfio_pci_core_open(struct vfio_device *core_vdev)
{
struct vfio_pci_core_device *vdev =
@@ -503,13 +489,13 @@ int vfio_pci_core_open(struct vfio_device *core_vdev)
lockdep_assert_held(&core_vdev->reflck->lock);
- ret = vfio_pci_enable(vdev);
+ ret = vfio_pci_core_enable(vdev);
if (ret)
- goto error;
- vfio_spapr_pci_eeh_open(vdev->pdev);
- vfio_pci_vf_token_user_add(vdev, 1);
-error:
- return ret;
+ return ret;
+
+ vfio_pci_core_finish_enable(vdev);
+
+ return 0;
}
static int vfio_pci_get_irq_count(struct vfio_pci_core_device *vdev, int irq_type)
diff --git a/drivers/vfio/pci/vfio_pci_core.h b/drivers/vfio/pci/vfio_pci_core.h
index 245862d5d6e4..406e934e23b2 100644
--- a/drivers/vfio/pci/vfio_pci_core.h
+++ b/drivers/vfio/pci/vfio_pci_core.h
@@ -227,5 +227,13 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count);
int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf);
int vfio_pci_core_reflck_attach(struct vfio_device *core_vdev);
+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);
+
+static inline bool vfio_pci_is_vga(struct pci_dev *pdev)
+{
+ return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
+}
#endif /* VFIO_PCI_CORE_H */
--
2.21.0
next prev parent reply other threads:[~2021-06-03 16:09 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-03 16:07 [RFC PATCH v4 00/11] Introduce vfio-pci-core subsystem Max Gurtovoy
2021-06-03 16:07 ` [PATCH 01/11] vfio-pci: rename vfio_pci.c to vfio_pci_core.c Max Gurtovoy
2021-06-03 16:08 ` [PATCH 02/11] vfio-pci: rename vfio_pci_private.h to vfio_pci_core.h Max Gurtovoy
2021-06-03 16:08 ` [PATCH 03/11] vfio-pci: rename vfio_pci_device to vfio_pci_core_device Max Gurtovoy
2021-06-03 16:08 ` [PATCH 04/11] vfio-pci: rename ops functions to fit core namings Max Gurtovoy
2021-06-03 16:08 ` [PATCH 05/11] vfio-pci: include vfio header in vfio_pci_core.h Max Gurtovoy
2021-06-03 16:08 ` [PATCH 06/11] vfio-pci: introduce vfio_pci.c Max Gurtovoy
2021-06-03 16:08 ` Max Gurtovoy [this message]
2021-06-03 16:08 ` [PATCH 08/11] PCI: add flags field to pci_device_id structure Max Gurtovoy
2021-06-03 16:08 ` [PATCH 09/11] PCI: add matching checks for driver_override binding Max Gurtovoy
2021-06-08 21:26 ` Alex Williamson
2021-06-08 22:45 ` Jason Gunthorpe
2021-06-09 1:27 ` Alex Williamson
2021-06-09 9:26 ` Max Gurtovoy
2021-06-13 8:19 ` Max Gurtovoy
2021-06-14 5:40 ` Christoph Hellwig
2021-06-14 8:18 ` Max Gurtovoy
2021-06-14 15:27 ` Christoph Hellwig
2021-06-14 16:01 ` Jason Gunthorpe
2021-06-14 16:15 ` Christoph Hellwig
2021-06-14 16:33 ` Jason Gunthorpe
2021-06-14 18:42 ` Alex Williamson
2021-06-14 23:12 ` Max Gurtovoy
2021-06-15 15:00 ` Alex Williamson
2021-06-15 15:04 ` Jason Gunthorpe
2021-06-15 16:20 ` Alex Williamson
2021-06-15 20:42 ` Jason Gunthorpe
2021-06-15 21:59 ` Alex Williamson
2021-06-15 23:00 ` Jason Gunthorpe
2021-06-15 23:22 ` Alex Williamson
2021-06-15 23:32 ` Jason Gunthorpe
2021-06-16 0:22 ` Alex Williamson
2021-06-16 0:34 ` Jason Gunthorpe
2021-06-16 23:28 ` Max Gurtovoy
2021-06-16 23:33 ` Jason Gunthorpe
2021-06-16 23:42 ` Max Gurtovoy
2021-06-16 23:44 ` Jason Gunthorpe
2021-06-16 23:51 ` Max Gurtovoy
2021-06-16 23:56 ` Jason Gunthorpe
2021-06-20 14:46 ` Max Gurtovoy
2021-06-03 16:08 ` [PATCH 10/11] vfio-pci: introduce vfio_pci_core subsystem driver Max Gurtovoy
2021-06-08 21:26 ` Alex Williamson
2021-06-09 9:29 ` Max Gurtovoy
2021-06-03 16:08 ` [PATCH 11/11] mlx5-vfio-pci: add new vfio_pci driver for mlx5 devices Max Gurtovoy
2021-07-30 7:53 ` [RFC PATCH v4 00/11] Introduce vfio-pci-core subsystem Shameerali Kolothum Thodi
2021-07-30 11:55 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210603160809.15845-8-mgurtovoy@nvidia.com \
--to=mgurtovoy@nvidia.com \
--cc=ACurrid@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=artemp@nvidia.com \
--cc=aviadye@nvidia.com \
--cc=cjia@nvidia.com \
--cc=cohuck@redhat.com \
--cc=hch@infradead.org \
--cc=jgg@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=oren@nvidia.com \
--cc=parav@nvidia.com \
--cc=shahafs@nvidia.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=targupta@nvidia.com \
--cc=yan.y.zhao@intel.com \
--cc=yishaih@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).