Skip to content

Commit bd45d46

Browse files
mwiniarsThomas Hellström
authored andcommitted
drm/xe/pf: Export helpers for VFIO
Device specific VFIO driver variant for Xe will implement VF migration. Export everything that's needed for migration ops. Reviewed-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Link: https://patch.msgid.link/20251127093934.1462188-4-michal.winiarski@intel.com Signed-off-by: Michał Winiarski <michal.winiarski@intel.com> (cherry picked from commit 17f2246) Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
1 parent 5be29eb commit bd45d46

3 files changed

Lines changed: 227 additions & 0 deletions

File tree

drivers/gpu/drm/xe/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ xe-$(CONFIG_PCI_IOV) += \
184184
xe_sriov_pf_sysfs.o \
185185
xe_tile_sriov_pf_debugfs.o
186186

187+
ifeq ($(CONFIG_PCI_IOV),y)
188+
xe-$(CONFIG_XE_VFIO_PCI) += xe_sriov_vfio.o
189+
endif
190+
187191
# include helpers for tests even when XE is built-in
188192
ifdef CONFIG_DRM_XE_KUNIT_TEST
189193
xe-y += tests/xe_kunit_helpers.o

drivers/gpu/drm/xe/xe_sriov_vfio.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: MIT
2+
/*
3+
* Copyright © 2025 Intel Corporation
4+
*/
5+
6+
#include <drm/intel/xe_sriov_vfio.h>
7+
#include <linux/cleanup.h>
8+
9+
#include "xe_pci.h"
10+
#include "xe_pm.h"
11+
#include "xe_sriov_pf_control.h"
12+
#include "xe_sriov_pf_helpers.h"
13+
#include "xe_sriov_pf_migration.h"
14+
15+
struct xe_device *xe_sriov_vfio_get_pf(struct pci_dev *pdev)
16+
{
17+
return xe_pci_to_pf_device(pdev);
18+
}
19+
EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_get_pf, "xe-vfio-pci");
20+
21+
bool xe_sriov_vfio_migration_supported(struct xe_device *xe)
22+
{
23+
if (!IS_SRIOV_PF(xe))
24+
return -EPERM;
25+
26+
return xe_sriov_pf_migration_supported(xe);
27+
}
28+
EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_migration_supported, "xe-vfio-pci");
29+
30+
#define DEFINE_XE_SRIOV_VFIO_FUNCTION(_type, _func, _impl) \
31+
_type xe_sriov_vfio_##_func(struct xe_device *xe, unsigned int vfid) \
32+
{ \
33+
if (!IS_SRIOV_PF(xe)) \
34+
return -EPERM; \
35+
if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe)) \
36+
return -EINVAL; \
37+
\
38+
guard(xe_pm_runtime_noresume)(xe); \
39+
\
40+
return xe_sriov_pf_##_impl(xe, vfid); \
41+
} \
42+
EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_##_func, "xe-vfio-pci")
43+
44+
DEFINE_XE_SRIOV_VFIO_FUNCTION(int, wait_flr_done, control_wait_flr);
45+
DEFINE_XE_SRIOV_VFIO_FUNCTION(int, suspend_device, control_pause_vf);
46+
DEFINE_XE_SRIOV_VFIO_FUNCTION(int, resume_device, control_resume_vf);
47+
DEFINE_XE_SRIOV_VFIO_FUNCTION(int, stop_copy_enter, control_trigger_save_vf);
48+
DEFINE_XE_SRIOV_VFIO_FUNCTION(int, stop_copy_exit, control_finish_save_vf);
49+
DEFINE_XE_SRIOV_VFIO_FUNCTION(int, resume_data_enter, control_trigger_restore_vf);
50+
DEFINE_XE_SRIOV_VFIO_FUNCTION(int, resume_data_exit, control_finish_restore_vf);
51+
DEFINE_XE_SRIOV_VFIO_FUNCTION(int, error, control_stop_vf);
52+
DEFINE_XE_SRIOV_VFIO_FUNCTION(ssize_t, stop_copy_size, migration_size);
53+
54+
ssize_t xe_sriov_vfio_data_read(struct xe_device *xe, unsigned int vfid,
55+
char __user *buf, size_t len)
56+
{
57+
if (!IS_SRIOV_PF(xe))
58+
return -EPERM;
59+
if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
60+
return -EINVAL;
61+
62+
guard(xe_pm_runtime_noresume)(xe);
63+
64+
return xe_sriov_pf_migration_read(xe, vfid, buf, len);
65+
}
66+
EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_data_read, "xe-vfio-pci");
67+
68+
ssize_t xe_sriov_vfio_data_write(struct xe_device *xe, unsigned int vfid,
69+
const char __user *buf, size_t len)
70+
{
71+
if (!IS_SRIOV_PF(xe))
72+
return -EPERM;
73+
if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
74+
return -EINVAL;
75+
76+
guard(xe_pm_runtime_noresume)(xe);
77+
78+
return xe_sriov_pf_migration_write(xe, vfid, buf, len);
79+
}
80+
EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_data_write, "xe-vfio-pci");

include/drm/intel/xe_sriov_vfio.h

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/*
3+
* Copyright © 2025 Intel Corporation
4+
*/
5+
6+
#ifndef _XE_SRIOV_VFIO_H_
7+
#define _XE_SRIOV_VFIO_H_
8+
9+
#include <linux/types.h>
10+
11+
struct pci_dev;
12+
struct xe_device;
13+
14+
/**
15+
* xe_sriov_vfio_get_pf() - Get PF &xe_device.
16+
* @pdev: the VF &pci_dev device
17+
*
18+
* Return: pointer to PF &xe_device, NULL otherwise.
19+
*/
20+
struct xe_device *xe_sriov_vfio_get_pf(struct pci_dev *pdev);
21+
22+
/**
23+
* xe_sriov_vfio_migration_supported() - Check if migration is supported.
24+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
25+
*
26+
* Return: true if migration is supported, false otherwise.
27+
*/
28+
bool xe_sriov_vfio_migration_supported(struct xe_device *xe);
29+
30+
/**
31+
* xe_sriov_vfio_wait_flr_done() - Wait for VF FLR completion.
32+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
33+
* @vfid: the VF identifier (can't be 0)
34+
*
35+
* This function will wait until VF FLR is processed by PF on all tiles (or
36+
* until timeout occurs).
37+
*
38+
* Return: 0 on success or a negative error code on failure.
39+
*/
40+
int xe_sriov_vfio_wait_flr_done(struct xe_device *xe, unsigned int vfid);
41+
42+
/**
43+
* xe_sriov_vfio_suspend_device() - Suspend VF.
44+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
45+
* @vfid: the VF identifier (can't be 0)
46+
*
47+
* This function will pause VF on all tiles/GTs.
48+
*
49+
* Return: 0 on success or a negative error code on failure.
50+
*/
51+
int xe_sriov_vfio_suspend_device(struct xe_device *xe, unsigned int vfid);
52+
53+
/**
54+
* xe_sriov_vfio_resume_device() - Resume VF.
55+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
56+
* @vfid: the VF identifier (can't be 0)
57+
*
58+
* This function will resume VF on all tiles.
59+
*
60+
* Return: 0 on success or a negative error code on failure.
61+
*/
62+
int xe_sriov_vfio_resume_device(struct xe_device *xe, unsigned int vfid);
63+
64+
/**
65+
* xe_sriov_vfio_stop_copy_enter() - Initiate a VF device migration data save.
66+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
67+
* @vfid: the VF identifier (can't be 0)
68+
*
69+
* Return: 0 on success or a negative error code on failure.
70+
*/
71+
int xe_sriov_vfio_stop_copy_enter(struct xe_device *xe, unsigned int vfid);
72+
73+
/**
74+
* xe_sriov_vfio_stop_copy_exit() - Finish a VF device migration data save.
75+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
76+
* @vfid: the VF identifier (can't be 0)
77+
*
78+
* Return: 0 on success or a negative error code on failure.
79+
*/
80+
int xe_sriov_vfio_stop_copy_exit(struct xe_device *xe, unsigned int vfid);
81+
82+
/**
83+
* xe_sriov_vfio_resume_data_enter() - Initiate a VF device migration data restore.
84+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
85+
* @vfid: the VF identifier (can't be 0)
86+
*
87+
* Return: 0 on success or a negative error code on failure.
88+
*/
89+
int xe_sriov_vfio_resume_data_enter(struct xe_device *xe, unsigned int vfid);
90+
91+
/**
92+
* xe_sriov_vfio_resume_data_exit() - Finish a VF device migration data restore.
93+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
94+
* @vfid: the VF identifier (can't be 0)
95+
*
96+
* Return: 0 on success or a negative error code on failure.
97+
*/
98+
int xe_sriov_vfio_resume_data_exit(struct xe_device *xe, unsigned int vfid);
99+
100+
/**
101+
* xe_sriov_vfio_error() - Move VF device to error state.
102+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
103+
* @vfid: the VF identifier (can't be 0)
104+
*
105+
* Reset is needed to move it out of error state.
106+
*
107+
* Return: 0 on success or a negative error code on failure.
108+
*/
109+
int xe_sriov_vfio_error(struct xe_device *xe, unsigned int vfid);
110+
111+
/**
112+
* xe_sriov_vfio_data_read() - Read migration data from the VF device.
113+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
114+
* @vfid: the VF identifier (can't be 0)
115+
* @buf: start address of userspace buffer
116+
* @len: requested read size from userspace
117+
*
118+
* Return: number of bytes that has been successfully read,
119+
* 0 if no more migration data is available, -errno on failure.
120+
*/
121+
ssize_t xe_sriov_vfio_data_read(struct xe_device *xe, unsigned int vfid,
122+
char __user *buf, size_t len);
123+
/**
124+
* xe_sriov_vfio_data_write() - Write migration data to the VF device.
125+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
126+
* @vfid: the VF identifier (can't be 0)
127+
* @buf: start address of userspace buffer
128+
* @len: requested write size from userspace
129+
*
130+
* Return: number of bytes that has been successfully written, -errno on failure.
131+
*/
132+
ssize_t xe_sriov_vfio_data_write(struct xe_device *xe, unsigned int vfid,
133+
const char __user *buf, size_t len);
134+
/**
135+
* xe_sriov_vfio_stop_copy_size() - Get a size estimate of VF device migration data.
136+
* @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
137+
* @vfid: the VF identifier (can't be 0)
138+
*
139+
* Return: migration data size in bytes or a negative error code on failure.
140+
*/
141+
ssize_t xe_sriov_vfio_stop_copy_size(struct xe_device *xe, unsigned int vfid);
142+
143+
#endif

0 commit comments

Comments
 (0)