File Index
Files and directories
Sign in
FILE

xe_sriov_vfio.c

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/xe/xe_sriov_vfio.c C
 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
15struct xe_device *xe_sriov_vfio_get_pf(struct pci_dev *pdev)
16{
17	return xe_pci_to_pf_device(pdev);
18}
19EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_get_pf, "xe-vfio-pci");
20
21bool xe_sriov_vfio_migration_supported(struct xe_device *xe)
22{
23	if (!IS_SRIOV_PF(xe))
24		return false;
25
26	return xe_sriov_pf_migration_supported(xe);
27}
28EXPORT_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}										\
42EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_##_func, "xe-vfio-pci")
43
44DEFINE_XE_SRIOV_VFIO_FUNCTION(int, wait_flr_done, control_wait_flr);
45DEFINE_XE_SRIOV_VFIO_FUNCTION(int, suspend_device, control_pause_vf);
46DEFINE_XE_SRIOV_VFIO_FUNCTION(int, resume_device, control_resume_vf);
47DEFINE_XE_SRIOV_VFIO_FUNCTION(int, stop_copy_enter, control_trigger_save_vf);
48DEFINE_XE_SRIOV_VFIO_FUNCTION(int, stop_copy_exit, control_finish_save_vf);
49DEFINE_XE_SRIOV_VFIO_FUNCTION(int, resume_data_enter, control_trigger_restore_vf);
50DEFINE_XE_SRIOV_VFIO_FUNCTION(int, resume_data_exit, control_finish_restore_vf);
51DEFINE_XE_SRIOV_VFIO_FUNCTION(int, error, control_stop_vf);
52DEFINE_XE_SRIOV_VFIO_FUNCTION(ssize_t, stop_copy_size, migration_size);
53
54ssize_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}
66EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_data_read, "xe-vfio-pci");
67
68ssize_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}
80EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_data_write, "xe-vfio-pci");
~/ Read-only file preview.