Skip to content

Commit 2fb89f5

Browse files
mgurtovoyAlex Williamson
authored andcommitted
vfio/pci: Move igd initialization to vfio_pci.c
igd is related to the vfio_pci pci_driver implementation, move it out of vfio_pci_core.c. This is preparation for splitting vfio_pci.ko into 2 drivers. Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Link: https://lore.kernel.org/r/20210826103912.128972-8-yishaih@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent ff53edf commit 2fb89f5

3 files changed

Lines changed: 41 additions & 36 deletions

File tree

drivers/vfio/pci/vfio_pci.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,36 @@ static bool vfio_pci_is_denylisted(struct pci_dev *pdev)
8282
return true;
8383
}
8484

85+
static int vfio_pci_open_device(struct vfio_device *core_vdev)
86+
{
87+
struct vfio_pci_core_device *vdev =
88+
container_of(core_vdev, struct vfio_pci_core_device, vdev);
89+
struct pci_dev *pdev = vdev->pdev;
90+
int ret;
91+
92+
ret = vfio_pci_core_enable(vdev);
93+
if (ret)
94+
return ret;
95+
96+
if (vfio_pci_is_vga(pdev) &&
97+
pdev->vendor == PCI_VENDOR_ID_INTEL &&
98+
IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
99+
ret = vfio_pci_igd_init(vdev);
100+
if (ret && ret != -ENODEV) {
101+
pci_warn(pdev, "Failed to setup Intel IGD regions\n");
102+
vfio_pci_core_disable(vdev);
103+
return ret;
104+
}
105+
}
106+
107+
vfio_pci_core_finish_enable(vdev);
108+
109+
return 0;
110+
}
111+
85112
static const struct vfio_device_ops vfio_pci_ops = {
86113
.name = "vfio-pci",
87-
.open_device = vfio_pci_core_open_device,
114+
.open_device = vfio_pci_open_device,
88115
.close_device = vfio_pci_core_close_device,
89116
.ioctl = vfio_pci_core_ioctl,
90117
.read = vfio_pci_core_read,

drivers/vfio/pci/vfio_pci_core.c

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ static unsigned int vfio_pci_set_vga_decode(void *opaque, bool single_vga)
9191
return decodes;
9292
}
9393

94-
static inline bool vfio_pci_is_vga(struct pci_dev *pdev)
95-
{
96-
return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
97-
}
98-
9994
static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev)
10095
{
10196
struct resource *res;
@@ -166,7 +161,6 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev)
166161

167162
struct vfio_pci_group_info;
168163
static bool vfio_pci_dev_set_try_reset(struct vfio_device_set *dev_set);
169-
static void vfio_pci_disable(struct vfio_pci_core_device *vdev);
170164
static int vfio_pci_dev_set_hot_reset(struct vfio_device_set *dev_set,
171165
struct vfio_pci_group_info *groups);
172166

@@ -252,7 +246,7 @@ int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, pci_power_t stat
252246
return ret;
253247
}
254248

255-
static int vfio_pci_enable(struct vfio_pci_core_device *vdev)
249+
int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
256250
{
257251
struct pci_dev *pdev = vdev->pdev;
258252
int ret;
@@ -321,26 +315,11 @@ static int vfio_pci_enable(struct vfio_pci_core_device *vdev)
321315
if (!vfio_vga_disabled() && vfio_pci_is_vga(pdev))
322316
vdev->has_vga = true;
323317

324-
if (vfio_pci_is_vga(pdev) &&
325-
pdev->vendor == PCI_VENDOR_ID_INTEL &&
326-
IS_ENABLED(CONFIG_VFIO_PCI_IGD)) {
327-
ret = vfio_pci_igd_init(vdev);
328-
if (ret && ret != -ENODEV) {
329-
pci_warn(pdev, "Failed to setup Intel IGD regions\n");
330-
goto disable_exit;
331-
}
332-
}
333-
334-
vfio_pci_probe_mmaps(vdev);
335318

336319
return 0;
337-
338-
disable_exit:
339-
vfio_pci_disable(vdev);
340-
return ret;
341320
}
342321

343-
static void vfio_pci_disable(struct vfio_pci_core_device *vdev)
322+
void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
344323
{
345324
struct pci_dev *pdev = vdev->pdev;
346325
struct vfio_pci_dummy_resource *dummy_res, *tmp;
@@ -479,7 +458,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
479458

480459
vfio_pci_vf_token_user_add(vdev, -1);
481460
vfio_spapr_pci_eeh_release(vdev->pdev);
482-
vfio_pci_disable(vdev);
461+
vfio_pci_core_disable(vdev);
483462

484463
mutex_lock(&vdev->igate);
485464
if (vdev->err_trigger) {
@@ -493,19 +472,11 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
493472
mutex_unlock(&vdev->igate);
494473
}
495474

496-
int vfio_pci_core_open_device(struct vfio_device *core_vdev)
475+
void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev)
497476
{
498-
struct vfio_pci_core_device *vdev =
499-
container_of(core_vdev, struct vfio_pci_core_device, vdev);
500-
int ret = 0;
501-
502-
ret = vfio_pci_enable(vdev);
503-
if (ret)
504-
return ret;
505-
477+
vfio_pci_probe_mmaps(vdev);
506478
vfio_spapr_pci_eeh_open(vdev->pdev);
507479
vfio_pci_vf_token_user_add(vdev, 1);
508-
return 0;
509480
}
510481

511482
static int vfio_pci_get_irq_count(struct vfio_pci_core_device *vdev, int irq_type)

drivers/vfio/pci/vfio_pci_core.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
210210
void vfio_pci_core_cleanup(void);
211211
int vfio_pci_core_init(void);
212212
void vfio_pci_core_close_device(struct vfio_device *core_vdev);
213-
int vfio_pci_core_open_device(struct vfio_device *core_vdev);
214213
void vfio_pci_core_init_device(struct vfio_pci_core_device *vdev,
215214
struct pci_dev *pdev,
216215
const struct vfio_device_ops *vfio_pci_ops);
@@ -228,5 +227,13 @@ ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *bu
228227
int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma);
229228
void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count);
230229
int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf);
230+
int vfio_pci_core_enable(struct vfio_pci_core_device *vdev);
231+
void vfio_pci_core_disable(struct vfio_pci_core_device *vdev);
232+
void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev);
233+
234+
static inline bool vfio_pci_is_vga(struct pci_dev *pdev)
235+
{
236+
return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
237+
}
231238

232239
#endif /* VFIO_PCI_CORE_H */

0 commit comments

Comments
 (0)